~ubuntu-branches/ubuntu/intrepid/ruby1.8/intrepid-updates

« back to all changes in this revision

Viewing changes to lib/yaml/yamlnode.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# YAML::YamlNode class
 
3
#
 
4
require 'yaml/basenode'
 
5
 
 
6
module YAML
 
7
 
 
8
    #
 
9
    # YAML Generic Model container
 
10
    #
 
11
    class YamlNode
 
12
        include BaseNode
 
13
        attr_accessor :kind, :type_id, :value, :anchor
 
14
        def initialize( t, v )
 
15
            @type_id = t
 
16
            if Hash === v
 
17
                @kind = 'map'
 
18
                @value = {}
 
19
                v.each { |k,v|
 
20
                    @value[ k.transform ] = [ k, v ]
 
21
                }
 
22
            elsif Array === v
 
23
                @kind = 'seq'
 
24
                @value = v
 
25
            elsif String === v
 
26
                @kind = 'scalar'
 
27
                @value = v
 
28
            end
 
29
        end
 
30
 
 
31
        #
 
32
        # Transform this node fully into a native type
 
33
        #
 
34
        def transform
 
35
            t = nil
 
36
            if @value.is_a? Hash
 
37
                t = {}
 
38
                @value.each { |k,v|
 
39
                    t[ k ] = v[1].transform
 
40
                }
 
41
            elsif @value.is_a? Array
 
42
                t = []
 
43
                @value.each { |v|
 
44
                    t.push v.transform
 
45
                }
 
46
            else
 
47
                t = @value
 
48
            end
 
49
            YAML.transfer_method( @type_id, t )
 
50
        end
 
51
 
 
52
    end
 
53
 
 
54
end