Class: Constree::Node

Inherits:
Struct
  • Object
show all
Includes:
TreeGraph
Defined in:
lib/constree/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#constantObject

Returns the value of attribute constant

Returns:

  • (Object)

    the current value of constant



4
5
6
# File 'lib/constree/node.rb', line 4

def constant
  @constant
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/constree/node.rb', line 4

def name
  @name
end

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of parent



4
5
6
# File 'lib/constree/node.rb', line 4

def parent
  @parent
end

#refObject

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_graphObject



12
13
14
# File 'lib/constree/node.rb', line 12

def children_for_tree_graph
  @sub_consts ||= []
end

#display_nameObject



29
30
31
# File 'lib/constree/node.rb', line 29

def display_name
  (name || constant.name).to_s
end

#full_nameObject



33
34
35
# File 'lib/constree/node.rb', line 33

def full_name
  top? ? constant.name : "#{parent.full_name}::#{name}"
end

#label_for_tree_graphObject



8
9
10
# File 'lib/constree/node.rb', line 8

def label_for_tree_graph
  display_name + ' ' + type
end

#not_yet?(seen) ⇒ Boolean

Returns:

  • (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_nodesObject



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

Returns:

  • (Boolean)


25
26
27
# File 'lib/constree/node.rb', line 25

def top?
  parent ? false : true
end

#typeObject



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