Class: Syck::YamlNode

Inherits:
Object show all
Includes:
BaseNode
Defined in:
lib/syck/yamlnode.rb

Overview

YAML Generic Model container

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseNode

#[], #at, #children, #children_with_index, #emit, #match_path, #match_segment, #search, #select, #select!

Constructor Details

#initialize(t, v) ⇒ YamlNode

Returns a new instance of YamlNode.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/syck/yamlnode.rb', line 14

def initialize(t, v)
    @type_id = t
    if Hash === v
        @kind = 'map'
        @value = {}
        v.each {|key,val|
            @value[key.transform] = [key, val]
        }
    elsif Array === v
        @kind = 'seq'
        @value = v
    elsif String === v
        @kind = 'scalar'
        @value = v
    end
end

Instance Attribute Details

#anchorObject

Returns the value of attribute anchor


13
14
15
# File 'lib/syck/yamlnode.rb', line 13

def anchor
  @anchor
end

#kindObject

Returns the value of attribute kind


13
14
15
# File 'lib/syck/yamlnode.rb', line 13

def kind
  @kind
end

#type_idObject

Returns the value of attribute type_id


13
14
15
# File 'lib/syck/yamlnode.rb', line 13

def type_id
  @type_id
end

#valueObject

Returns the value of attribute value


13
14
15
# File 'lib/syck/yamlnode.rb', line 13

def value
  @value
end

Instance Method Details

#transformObject

Transform this node fully into a native type


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/syck/yamlnode.rb', line 34

def transform
    t = nil
    if @value.is_a? Hash
        t = {}
        @value.each { |k,v|
            t[ k ] = v[1].transform
        }
    elsif @value.is_a? Array
        t = []
        @value.each { |v|
            t.push v.transform
        }
    else
        t = @value
    end
    Syck.transfer_method( @type_id, t )
end