Class: Constree::Node
- Inherits:
-
Struct
- Object
- Struct
- Constree::Node
- Includes:
- TreeGraph
- Defined in:
- lib/constree/node.rb
Instance Attribute Summary collapse
-
#constant ⇒ Object
Returns the value of attribute constant.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#ref ⇒ Object
Returns the value of attribute ref.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #children_for_tree_graph ⇒ Object
- #display_name ⇒ Object
- #full_name ⇒ Object
- #label_for_tree_graph ⇒ Object
- #not_yet?(seen) ⇒ Boolean
- #sub_nodes ⇒ Object
- #top? ⇒ Boolean
- #type ⇒ Object
Instance Attribute Details
#constant ⇒ Object
Returns the value of attribute constant
4 5 6 |
# File 'lib/constree/node.rb', line 4 def constant @constant end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/constree/node.rb', line 4 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent
4 5 6 |
# File 'lib/constree/node.rb', line 4 def parent @parent end |
#ref ⇒ Object
Returns the value of attribute ref.
16 17 18 |
# File 'lib/constree/node.rb', line 16 def ref @ref end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 40 |
# File 'lib/constree/node.rb', line 37 def == other return false unless other.is_a? Node constant == other.constant end |
#children_for_tree_graph ⇒ Object
12 13 14 |
# File 'lib/constree/node.rb', line 12 def children_for_tree_graph @sub_consts ||= [] end |
#display_name ⇒ Object
29 30 31 |
# File 'lib/constree/node.rb', line 29 def display_name (name || constant.name).to_s end |
#full_name ⇒ Object
33 34 35 |
# File 'lib/constree/node.rb', line 33 def full_name top? ? constant.name : "#{parent.full_name}::#{name}" end |
#label_for_tree_graph ⇒ Object
8 9 10 |
# File 'lib/constree/node.rb', line 8 def label_for_tree_graph display_name + ' ' + type end |
#not_yet?(seen) ⇒ Boolean
48 49 50 51 52 53 54 55 56 |
# File 'lib/constree/node.rb', line 48 def not_yet? seen i = seen.find_index self if i == seen.count - 1 true else self.ref = seen[i] false end end |
#sub_nodes ⇒ Object
18 19 20 21 22 23 |
# File 'lib/constree/node.rb', line 18 def sub_nodes return [] unless constant.is_a? Module constant.constants.map do |name| Node.new(constant.const_get(name), name, self) end end |
#top? ⇒ Boolean
25 26 27 |
# File 'lib/constree/node.rb', line 25 def top? parent ? false : true end |
#type ⇒ Object
42 43 44 45 46 |
# File 'lib/constree/node.rb', line 42 def type return "→ #{ref.full_name}" if ref return "(#{constant.class.to_s})" unless Class === constant "< " + constant.ancestors[1..].map(&:to_s).join(" < ") end |