Class: Psych::Nodes::Node
- Includes:
- Enumerable
- Defined in:
- lib/psych/nodes/node.rb
Overview
The base class for any Node in a YAML parse tree. This class should never be instantiated.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
The children of this node.
-
#end_column ⇒ Object
The column number where this node ends.
-
#end_line ⇒ Object
The line number where this node ends.
-
#start_column ⇒ Object
The column number where this node start.
-
#start_line ⇒ Object
The line number where this node start.
-
#tag ⇒ Object
readonly
An associated tag.
Instance Method Summary collapse
- #alias? ⇒ Boolean
- #document? ⇒ Boolean
-
#each(&block) ⇒ Object
Iterate over each node in the tree.
-
#initialize ⇒ Node
constructor
Create a new Psych::Nodes::Node.
- #mapping? ⇒ Boolean
- #scalar? ⇒ Boolean
- #sequence? ⇒ Boolean
- #stream? ⇒ Boolean
-
#to_ruby ⇒ Object
(also: #transform)
Convert this node to Ruby.
-
#yaml(io = nil, options = {}) ⇒ Object
(also: #to_yaml)
Convert this node to YAML.
Constructor Details
#initialize ⇒ Node
Create a new Psych::Nodes::Node
33 34 35 |
# File 'lib/psych/nodes/node.rb', line 33 def initialize @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
The children of this node
15 16 17 |
# File 'lib/psych/nodes/node.rb', line 15 def children @children end |
#end_column ⇒ Object
The column number where this node ends
30 31 32 |
# File 'lib/psych/nodes/node.rb', line 30 def end_column @end_column end |
#end_line ⇒ Object
The line number where this node ends
27 28 29 |
# File 'lib/psych/nodes/node.rb', line 27 def end_line @end_line end |
#start_column ⇒ Object
The column number where this node start
24 25 26 |
# File 'lib/psych/nodes/node.rb', line 24 def start_column @start_column end |
#start_line ⇒ Object
The line number where this node start
21 22 23 |
# File 'lib/psych/nodes/node.rb', line 21 def start_line @start_line end |
#tag ⇒ Object (readonly)
An associated tag
18 19 20 |
# File 'lib/psych/nodes/node.rb', line 18 def tag @tag end |
Instance Method Details
#alias? ⇒ Boolean
67 |
# File 'lib/psych/nodes/node.rb', line 67 def alias?; false; end |
#document? ⇒ Boolean
68 |
# File 'lib/psych/nodes/node.rb', line 68 def document?; false; end |
#each(&block) ⇒ Object
Iterate over each node in the tree. Yields each node to block
depth first.
40 41 42 43 |
# File 'lib/psych/nodes/node.rb', line 40 def each &block return enum_for :each unless block_given? Visitors::DepthFirst.new(block).accept self end |
#mapping? ⇒ Boolean
69 |
# File 'lib/psych/nodes/node.rb', line 69 def mapping?; false; end |
#scalar? ⇒ Boolean
70 |
# File 'lib/psych/nodes/node.rb', line 70 def scalar?; false; end |
#sequence? ⇒ Boolean
71 |
# File 'lib/psych/nodes/node.rb', line 71 def sequence?; false; end |
#stream? ⇒ Boolean
72 |
# File 'lib/psych/nodes/node.rb', line 72 def stream?; false; end |
#to_ruby ⇒ Object Also known as: transform
Convert this node to Ruby.
See also Psych::Visitors::ToRuby
49 50 51 |
# File 'lib/psych/nodes/node.rb', line 49 def to_ruby Visitors::ToRuby.create.accept(self) end |
#yaml(io = nil, options = {}) ⇒ Object Also known as: to_yaml
Convert this node to YAML.
See also Psych::Visitors::Emitter
58 59 60 61 62 63 64 |
# File 'lib/psych/nodes/node.rb', line 58 def yaml io = nil, = {} real_io = io || StringIO.new(''.encode('utf-8')) Visitors::Emitter.new(real_io, ).accept self return real_io.string unless io io end |