Class: Tgui::TreeView::TreeNode
- Defined in:
- lib/white_gold/dsl/tree_view.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
- #[](*path, grow: false) ⇒ Object
- #cut(*path, last) ⇒ Object
-
#initialize(object) ⇒ TreeNode
constructor
A new instance of TreeNode.
- #path_str_to_object(path) ⇒ Object
Constructor Details
#initialize(object) ⇒ TreeNode
Returns a new instance of TreeNode.
44 45 46 47 |
# File 'lib/white_gold/dsl/tree_view.rb', line 44 def initialize object @object = object @nodes = {} end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
50 51 52 |
# File 'lib/white_gold/dsl/tree_view.rb', line 50 def nodes @nodes end |
#object ⇒ Object
Returns the value of attribute object.
49 50 51 |
# File 'lib/white_gold/dsl/tree_view.rb', line 49 def object @object end |
Instance Method Details
#[](*path, grow: false) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/white_gold/dsl/tree_view.rb', line 52 def [](*path, grow: false) if grow path.reduce(self){|node, str| node.nodes[str] ||= TreeNode.new nil } else path.reduce(self){|node, str| node&.nodes[str] } end end |
#cut(*path, last) ⇒ Object
60 61 62 |
# File 'lib/white_gold/dsl/tree_view.rb', line 60 def cut *path, last self[*path].nodes.delete last end |
#path_str_to_object(path) ⇒ Object
64 65 66 67 68 |
# File 'lib/white_gold/dsl/tree_view.rb', line 64 def path_str_to_object path objects = [] path.reduce(self){|node, str| node[str].tap{|n| objects << n.object } } objects end |