Class: ASTUtils::Navigation
- Inherits:
-
Object
- Object
- ASTUtils::Navigation
- Includes:
- NodeHelper
- Defined in:
- lib/ast_utils/navigation.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#parents ⇒ Object
readonly
Returns the value of attribute parents.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #construct ⇒ Object
-
#initialize(node:) ⇒ Navigation
constructor
A new instance of Navigation.
- #parent(node) ⇒ Object
- #set_parent(node) ⇒ Object
Methods included from NodeHelper
#each_child_node, #map_child_node
Constructor Details
#initialize(node:) ⇒ Navigation
Returns a new instance of Navigation.
9 10 11 12 13 |
# File 'lib/ast_utils/navigation.rb', line 9 def initialize(node:) @root = node @nodes = NodeSet.new @parents = {} end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
5 6 7 |
# File 'lib/ast_utils/navigation.rb', line 5 def nodes @nodes end |
#parents ⇒ Object (readonly)
Returns the value of attribute parents.
6 7 8 |
# File 'lib/ast_utils/navigation.rb', line 6 def parents @parents end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/ast_utils/navigation.rb', line 7 def root @root end |
Class Method Details
.from(node:) ⇒ Object
32 33 34 |
# File 'lib/ast_utils/navigation.rb', line 32 def self.from(node:) new(node: node).tap {|nav| nav.construct } end |
Instance Method Details
#construct ⇒ Object
15 16 17 |
# File 'lib/ast_utils/navigation.rb', line 15 def construct set_parent(root) end |
#parent(node) ⇒ Object
28 29 30 |
# File 'lib/ast_utils/navigation.rb', line 28 def parent(node) parents[node.__id__] end |
#set_parent(node) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ast_utils/navigation.rb', line 19 def set_parent(node) nodes << node each_child_node(node) do |child| parents[child.__id__] = node set_parent(child) end end |