Class: TreeRepl::NamedNode

Inherits:
TreeNode show all
Defined in:
lib/treerepl/tree.rb

Instance Attribute Summary collapse

Attributes inherited from TreeNode

#leaf, #parent

Instance Method Summary collapse

Methods inherited from TreeNode

#children

Constructor Details

#initialize(obj, name) ⇒ NamedNode



46
47
48
49
# File 'lib/treerepl/tree.rb', line 46

def initialize(obj,name)
  @obj = obj
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



45
46
47
# File 'lib/treerepl/tree.rb', line 45

def name
  @name
end

#objObject (readonly)

Returns the value of attribute obj.



44
45
46
# File 'lib/treerepl/tree.rb', line 44

def obj
  @obj
end

Instance Method Details

#find_childrenObject

Creates the children from the provided symbols defined by implementing symbols()



53
54
55
56
57
58
59
60
# File 'lib/treerepl/tree.rb', line 53

def find_children
  lst = symbols
  if lst.is_a? Hash
    lst.keys.sort.map {|n| CmdNode.new @obj,lst[n],n}
  else
    lst.sort {|a,b| a.to_s <=> b.to_s}.map {|n| CmdNode.new @obj,n,nil}
  end
end

#symbolsObject

-> [symbol] | => symbol

The symbols (with possible) mapped names to use for children



66
67
68
# File 'lib/treerepl/tree.rb', line 66

def symbols
  raise 'Implement symbols()'
end