Module: Tree::ExternalChildrenArrayImplementation

Includes:
ChildrenImplementation, NodeProperty
Included in:
NestedArrayTree
Defined in:
lib/modular_tree/implementations.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Implementation

#initialize

Methods included from BranchesProperty

#bare?

Methods included from ChildrenProperty

#detach

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



78
79
80
# File 'lib/modular_tree/implementations.rb', line 78

def array
  @array
end

Class Method Details

.new(array) ⇒ Object



106
107
108
109
110
# File 'lib/modular_tree/implementations.rb', line 106

def self.new(array)
  object = super(nil)
  object.array = array
  object
end

Instance Method Details

#attach(child) ⇒ Object

protected



113
# File 'lib/modular_tree/implementations.rb', line 113

def attach(child) = array.last << child

#branchesObject



81
# File 'lib/modular_tree/implementations.rb', line 81

def branches = Enumerator.new { |enum| each_branch { |branch| enum << branch } }

#childrenObject



80
# File 'lib/modular_tree/implementations.rb', line 80

def children = @array.last.map(&:first)

#each(&block) ⇒ Object



98
99
100
# File 'lib/modular_tree/implementations.rb', line 98

def each(&block)
  @array.last.map.with_index { |node, i| yield i, self.class.new(node) }
end

#each_branch(&block) ⇒ Object

def each_child(&block) = array.last.each(&:first)



88
89
90
91
92
# File 'lib/modular_tree/implementations.rb', line 88

def each_branch(&block)
  block_given? or raise ArgumentError
#     impl = self.class.new(nil)
  @array.last.map { |node| yield self.class.new(node) }
end

#each_child(&block) ⇒ Object

FIXME: each_child/branch/etc. are actually map methods



84
85
86
# File 'lib/modular_tree/implementations.rb', line 84

def each_child(&block) = @array.last.map { |*node| yield(*node) }
#   def each_child(&block) = array.second.each { |node| yield(*node, self) } # Actually possible
#   def each_child(&block) = array.last.each(&:first)

#each_edge(&block) ⇒ Object



94
95
96
# File 'lib/modular_tree/implementations.rb', line 94

def each_edge(&block)
  @array.last.map { |node| yield self, self.class.new(node) }
end

#each_node(&block) ⇒ Object



102
103
104
# File 'lib/modular_tree/implementations.rb', line 102

def each_node(&block)
  @array.last.map.with_index { |node, i| yield self, i, self.class.new(node) }
end

#nodeObject



74
# File 'lib/modular_tree/implementations.rb', line 74

def node = array

#node_valueObject

FIXME What is this? It is a problem several places



76
# File 'lib/modular_tree/implementations.rb', line 76

def node_value = array.first # FIXME What is this? It is a problem several places

#thisObject



75
# File 'lib/modular_tree/implementations.rb', line 75

def this = array.first