Class: Constree::Node
- Inherits:
-
Struct
- Object
- Struct
- Constree::Node
- Includes:
- TreeGraph, TreeHtml
- Defined in:
- lib/constree/node.rb
Direct Known Subclasses
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 (also: #children_for_tree_html)
- #css_for_tree_html ⇒ Object
- #display_name ⇒ Object
- #full_name ⇒ Object
- #label_for_tree_graph ⇒ Object
- #label_for_tree_html ⇒ Object
- #not_yet?(seen) ⇒ Boolean
- #sub_nodes ⇒ Object
- #top? ⇒ Boolean
- #verbose ⇒ Object
Instance Attribute Details
#constant ⇒ Object
Returns the value of attribute constant
5 6 7 |
# File 'lib/constree/node.rb', line 5 def constant @constant end |
#name ⇒ Object
Returns the value of attribute name
5 6 7 |
# File 'lib/constree/node.rb', line 5 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent
5 6 7 |
# File 'lib/constree/node.rb', line 5 def parent @parent end |
#ref ⇒ Object
Returns the value of attribute ref.
29 30 31 |
# File 'lib/constree/node.rb', line 29 def ref @ref end |
Instance Method Details
#==(other) ⇒ Object
51 52 53 54 55 |
# File 'lib/constree/node.rb', line 51 def == other return false unless constant.is_a? Module return false unless other.is_a? Node constant == other.constant end |
#children_for_tree_graph ⇒ Object Also known as: children_for_tree_html
13 14 15 |
# File 'lib/constree/node.rb', line 13 def children_for_tree_graph @sub_consts ||= [] end |
#css_for_tree_html ⇒ Object
25 26 27 |
# File 'lib/constree/node.rb', line 25 def css_for_tree_html '.hl{color: coral;}' end |
#display_name ⇒ Object
43 44 45 |
# File 'lib/constree/node.rb', line 43 def display_name (name || constant.name).to_s end |
#full_name ⇒ Object
47 48 49 |
# File 'lib/constree/node.rb', line 47 def full_name top? ? constant.name : "#{parent.full_name}::#{name}" end |
#label_for_tree_graph ⇒ Object
9 10 11 |
# File 'lib/constree/node.rb', line 9 def label_for_tree_graph "#{display_name} #{verbose}" end |
#label_for_tree_html ⇒ Object
19 20 21 |
# File 'lib/constree/node.rb', line 19 def label_for_tree_html "<span class='hl'>#{display_name}</span> #{verbose}" end |
#not_yet?(seen) ⇒ Boolean
75 76 77 78 79 80 81 82 83 |
# File 'lib/constree/node.rb', line 75 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
31 32 33 34 35 36 37 |
# File 'lib/constree/node.rb', line 31 def sub_nodes return [] unless constant.is_a? Module constant.constants.sort!.map! do |name| const_value = constant.const_get(name) Node.new(const_value, name, self) end end |
#top? ⇒ Boolean
39 40 41 |
# File 'lib/constree/node.rb', line 39 def top? parent ? false : true end |
#verbose ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/constree/node.rb', line 57 def verbose return {ref: ref.full_name} if ref info = {kla: constant.class} return info unless constant.is_a? Module ancestors = constant.ancestors idx = ancestors.index(constant) if idx > 0 && !(before = ancestors[0 .. (idx - 1)]).empty? info[:bef] = before end unless (after = ancestors[(idx + 1) .. -1]).empty? info[:aft] = after end info end |