Class: RbYAML::Composer
- Included in:
- RbYAMLTester2, RbYAMLTester3
- Defined in:
- lib/rbyaml/composer.rb
Instance Method Summary collapse
- #check_node ⇒ Object
- #compose_document ⇒ Object
- #compose_mapping_node(anchor) ⇒ Object
- #compose_node(parent, index) ⇒ Object
- #compose_scalar_node(anchor) ⇒ Object
- #compose_sequence_node(anchor) ⇒ Object
- #each_node ⇒ Object
- #get_node ⇒ Object
-
#initialize(parser, resolver) ⇒ Composer
constructor
A new instance of Composer.
Constructor Details
#initialize(parser, resolver) ⇒ Composer
Returns a new instance of Composer.
10 11 12 13 14 |
# File 'lib/rbyaml/composer.rb', line 10 def initialize(parser,resolver) @parser = parser @resolver = resolver @anchors = {} end |
Instance Method Details
#check_node ⇒ Object
16 17 18 |
# File 'lib/rbyaml/composer.rb', line 16 def check_node !@parser.peek_event.__is_stream_end end |
#compose_document ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rbyaml/composer.rb', line 28 def compose_document # Drop the STREAM-START event. @parser.get_event if @parser.peek_event.__is_stream_start # Drop the DOCUMENT-START event. @parser.get_event # Compose the root node. node = compose_node(nil,nil) # Drop the DOCUMENT-END event. @parser.get_event @anchors = {} node end |
#compose_mapping_node(anchor) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rbyaml/composer.rb', line 92 def compose_mapping_node(anchor) start_event = @parser.get_event tag = start_event.tag tag = @resolver.resolve(MappingNode,nil,start_event.implicit) if tag.nil? || tag == "!" node = MappingNode.new(tag, {},start_event.start_mark,nil,start_event.flow_style) @anchors[anchor] = node if !anchor.nil? while !@parser.peek_event.__is_mapping_end key_event = @parser.peek_event item_key = compose_node(node,nil) if node.value.include?(item_key) raise ComposerError.new("while composing a mapping", start_event.start_mark,"found duplicate key", key_event.start_mark) end item_value = compose_node(node,item_key) node.value[item_key] = item_value end end_event = @parser.get_event node.end_mark = end_event.end_mark node end |
#compose_node(parent, index) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rbyaml/composer.rb', line 41 def compose_node(parent,index) if @parser.peek_event.__is_alias event = @parser.get_event anchor = event.anchor raise ComposerError.new(nil, nil, "found undefined alias #{anchor}", event.start_mark) if !@anchors.include?(anchor) return @anchors[anchor] end event = @parser.peek_event anchor = event.anchor if !anchor.nil? if @anchors.include?(anchor) raise ComposerError.new("found duplicate anchor #{anchor}; first occurence", @anchors[anchor].start_mark,"second occurence", event.start_mark) end end @resolver.descend_resolver(parent,index) if @parser.peek_event.__is_scalar node = compose_scalar_node(anchor) elsif @parser.peek_event.__is_sequence_start node = compose_sequence_node(anchor) elsif @parser.peek_event.__is_mapping_start node = compose_mapping_node(anchor) end @resolver.ascend_resolver node end |
#compose_scalar_node(anchor) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/rbyaml/composer.rb', line 67 def compose_scalar_node(anchor) event = @parser.get_event tag = event.tag tag = @resolver.resolve(ScalarNode,event.value,event.implicit) if tag.nil? || tag == "!" node = ScalarNode.new(tag, event.value,event.start_mark, event.end_mark, event.style) @anchors[anchor] = node if !anchor.nil? node end |
#compose_sequence_node(anchor) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rbyaml/composer.rb', line 76 def compose_sequence_node(anchor) start_event = @parser.get_event tag = start_event.tag tag = @resolver.resolve(SequenceNode,nil,start_event.implicit) if tag.nil? || tag == "!" node = SequenceNode.new(tag,[],start_event.start_mark,nil,start_event.flow_style) @anchors[anchor] = node if !anchor.nil? index = 0 while !@parser.peek_event.__is_sequence_end node.value << compose_node(node,index) index += 1 end end_event = @parser.get_event node.end_mark = end_event.end_mark node end |
#each_node ⇒ Object
24 25 26 |
# File 'lib/rbyaml/composer.rb', line 24 def each_node yield compose_document while check_node end |
#get_node ⇒ Object
20 21 22 |
# File 'lib/rbyaml/composer.rb', line 20 def get_node compose_document if check_node end |