Class: Psych::Nodes::Node

Inherits:
Object show all
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.

Direct Known Subclasses

Alias, Document, Mapping, Scalar, Sequence, Stream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

Create a new Psych::Nodes::Node



32
33
34
# File 'lib/psych/nodes/node.rb', line 32

def initialize
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

The children of this node



14
15
16
# File 'lib/psych/nodes/node.rb', line 14

def children
  @children
end

#end_columnObject

The column number where this node ends



29
30
31
# File 'lib/psych/nodes/node.rb', line 29

def end_column
  @end_column
end

#end_lineObject

The line number where this node ends



26
27
28
# File 'lib/psych/nodes/node.rb', line 26

def end_line
  @end_line
end

#start_columnObject

The column number where this node start



23
24
25
# File 'lib/psych/nodes/node.rb', line 23

def start_column
  @start_column
end

#start_lineObject

The line number where this node start



20
21
22
# File 'lib/psych/nodes/node.rb', line 20

def start_line
  @start_line
end

#tagObject (readonly)

An associated tag



17
18
19
# File 'lib/psych/nodes/node.rb', line 17

def tag
  @tag
end

Instance Method Details

#alias?Boolean

Returns:

  • (Boolean)


67
# File 'lib/psych/nodes/node.rb', line 67

def alias?;    false; end

#document?Boolean

Returns:

  • (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.



39
40
41
42
# File 'lib/psych/nodes/node.rb', line 39

def each &block
  return enum_for :each unless block_given?
  Visitors::DepthFirst.new(block).accept self
end

#mapping?Boolean

Returns:

  • (Boolean)


69
# File 'lib/psych/nodes/node.rb', line 69

def mapping?;  false; end

#scalar?Boolean

Returns:

  • (Boolean)


70
# File 'lib/psych/nodes/node.rb', line 70

def scalar?;   false; end

#sequence?Boolean

Returns:

  • (Boolean)


71
# File 'lib/psych/nodes/node.rb', line 71

def sequence?; false; end

#stream?Boolean

Returns:

  • (Boolean)


72
# File 'lib/psych/nodes/node.rb', line 72

def stream?;   false; end

#to_ruby(symbolize_names: false, freeze: false, strict_integer: false) ⇒ Object Also known as: transform

Convert this node to Ruby.

See also Psych::Visitors::ToRuby



48
49
50
# File 'lib/psych/nodes/node.rb', line 48

def to_ruby(symbolize_names: false, freeze: false, strict_integer: false)
  Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze, strict_integer: strict_integer).accept(self)
end

#yaml(io = nil, options = {}) ⇒ Object Also known as: to_yaml

Convert this node to YAML.

See also Psych::Visitors::Emitter



57
58
59
60
61
62
63
64
# File 'lib/psych/nodes/node.rb', line 57

def yaml io = nil, options = {}
  require "stringio"
  real_io = io || StringIO.new(''.encode('utf-8'))

  Visitors::Emitter.new(real_io, options).accept self
  return real_io.string unless io
  io
end