Class: TreeHaver::Backends::Psych::Tree

Inherits:
TreeHaver::Base::Tree show all
Defined in:
lib/tree_haver/backends/psych.rb

Overview

Psych tree wrapper

Wraps a Psych::Nodes::Stream to provide TreeHaver-compatible tree interface.

Instance Attribute Summary collapse

Attributes inherited from TreeHaver::Base::Tree

#lines, #source

Instance Method Summary collapse

Methods inherited from TreeHaver::Base::Tree

#comments, #edit, #errors, #has_error?, #warnings

Constructor Details

#initialize(stream, source) ⇒ Tree

Create a new tree wrapper

Parameters:

  • stream (::Psych::Nodes::Stream)

    Psych stream node

  • source (String)

    Original source



163
164
165
# File 'lib/tree_haver/backends/psych.rb', line 163

def initialize(stream, source)
  super(stream, source: source)
end

Instance Attribute Details

#inner_tree::Psych::Nodes::Stream (readonly)

Returns The underlying Psych stream.

Returns:

  • (::Psych::Nodes::Stream)

    The underlying Psych stream



157
158
159
# File 'lib/tree_haver/backends/psych.rb', line 157

def inner_tree
  @inner_tree
end

Instance Method Details

#inspectObject

Human-readable representation



175
176
177
# File 'lib/tree_haver/backends/psych.rb', line 175

def inspect
  "#<TreeHaver::Backends::Psych::Tree documents=#{inner_tree.children&.size || 0}>"
end

#root_nodeNode

Get the root node

Returns:

  • (Node)

    Root node



170
171
172
# File 'lib/tree_haver/backends/psych.rb', line 170

def root_node
  Node.new(inner_tree, source: source, lines: lines)
end