Class: Tgui::MenuBar::TreeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/white_gold/dsl/menu_bar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ TreeNode

Returns a new instance of TreeNode.



67
68
69
70
# File 'lib/white_gold/dsl/menu_bar.rb', line 67

def initialize text
  @text = text
  @nodes = {}
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



73
74
75
# File 'lib/white_gold/dsl/menu_bar.rb', line 73

def nodes
  @nodes
end

#textObject

Returns the value of attribute text.



72
73
74
# File 'lib/white_gold/dsl/menu_bar.rb', line 72

def text
  @text
end

Instance Method Details

#[](*path, grow: false) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/white_gold/dsl/menu_bar.rb', line 75

def [](*path, grow: false)
  if grow
    path.reduce(self){|node, o| node.nodes[o] ||= TreeNode.new(nil) }
  else
    path.reduce(self){|node, o| node&.nodes[o] }
  end
end

#cut(*path, last) ⇒ Object



83
84
85
# File 'lib/white_gold/dsl/menu_bar.rb', line 83

def cut *path, last
  self[*path].nodes.delete last
end

#cut_branches(*path) ⇒ Object



87
88
89
# File 'lib/white_gold/dsl/menu_bar.rb', line 87

def cut_branches *path
  self[*path].nodes = {}
end

#path_object_to_str(*path) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/white_gold/dsl/menu_bar.rb', line 101

def path_object_to_str *path
  str_path = []
  path.reduce self do |node, o|
    node[o].tap{ str_path << _1.text }
  end
  str_path
end

#path_str_to_object(*path) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/white_gold/dsl/menu_bar.rb', line 91

def path_str_to_object *path
  object_path = []
  path.reduce self do |node, str|
    o, node = *node.nodes.find{|k, v| v.text == str }
    object_path << o
    node
  end
  object_path
end