Class: ArrayNodeBuilder

Inherits:
Object show all
Includes:
SourceCodeDumpable
Defined in:
lib/rpdf2txt-rockit/syntax_tree.rb

Overview

Builder for arrays. You specify the indices for the children values that should be collected into an Array element and (optionally) give the index to an Array to append the element to.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SourceCodeDumpable

as_code, as_method_named, as_module_method_named, #create_new, indent_lines, name_hash, #new_of_my_type, #parameter_named, #to_compact_src, #to_src_in_module, #type_to_src

Constructor Details

#initialize(indices = [], arrayIndex = nil, chainedTreeBuilder = nil, insertAtIndex = nil, deleteIndices = [], append_element = true) ⇒ ArrayNodeBuilder

Returns a new instance of ArrayNodeBuilder.



158
159
160
161
162
163
164
165
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 158

def initialize(indices = [], arrayIndex = nil,
 chainedTreeBuilder = nil, insertAtIndex = nil,
 deleteIndices = [], append_element = true)
  @indices, @array_index = indices, arrayIndex
  @append_element, @shifting_insert = append_element, false
  chainedTreeBuilder = SyntaxTreeBuilder.new("ArrayNode", []) unless chainedTreeBuilder
  chain_treebuilder(chainedTreeBuilder, insertAtIndex, deleteIndices)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methodId, *args) ⇒ Object



230
231
232
233
234
235
236
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 230

def method_missing(methodId, *args)
  begin
    @chained_treebuilder.send(methodId, *args)
  rescue Exception
    super
  end
end

Instance Attribute Details

#append_elementObject

Returns the value of attribute append_element.



156
157
158
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 156

def append_element
  @append_element
end

#array_indexObject (readonly)

Returns the value of attribute array_index.



155
156
157
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 155

def array_index
  @array_index
end

#indicesObject (readonly)

Returns the value of attribute indices.



155
156
157
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 155

def indices
  @indices
end

#shifting_insertObject

Returns the value of attribute shifting_insert.



156
157
158
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 156

def shifting_insert
  @shifting_insert
end

Instance Method Details

#==(other) ⇒ Object



212
213
214
215
216
217
218
219
220
221
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 212

def ==(other)
  other.class == self.class and
    other.indices == indices and other.array_index == array_index and
    (@insert_at_index ? 
      (other.instance_eval("@chained_treebuilder") == @chained_treebuilder and
other.instance_eval("@insert_at_index") == @insert_at_index and
other.instance_eval("@delete_indices") == @delete_indices) :
     true) and
    other.append_element == @append_element
end

#activate_child(child) ⇒ Object



198
199
200
201
202
203
204
205
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 198

def activate_child(child)
  if child.kind_of?(Integer) and 
	child >= @insert_at_index
    @chained_treebuilder.activate_child(child+1)
  else
    @chained_treebuilder.activate_child(child)
  end
end

#chain_treebuilder(chainedTreeBuilder, insertAtIndex, deleteIndices = []) ⇒ Object



207
208
209
210
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 207

def chain_treebuilder(chainedTreeBuilder, insertAtIndex, deleteIndices = [])
  @chained_treebuilder = chainedTreeBuilder
  @insert_at_index, @delete_indices = insertAtIndex, deleteIndices
end

#copyObject



167
168
169
170
171
172
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 167

def copy
  n = ArrayNodeBuilder.new(@indices, @array_index, @chained_treebuilder.copy,
	 @insert_at_index, @delete_indices)
  n.shifting_insert = @shifting_insert
  n
end

#create_tree(childrenValues) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 174

def create_tree(childrenValues)
  tree = create_tree_basic(childrenValues)
  if @chained_treebuilder and @insert_at_index
    if @shifting_insert
	childrenValues[@insert_at_index, 0] = tree
    else
	childrenValues[@insert_at_index, 1] = tree
    end
    childrenValues = childrenValues.delete_at_indices(@delete_indices)
    return @chained_treebuilder.create_tree(childrenValues)
  else
    return tree
  end
end

#inactivate_child(child) ⇒ Object



189
190
191
192
193
194
195
196
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 189

def inactivate_child(child)
  if child.kind_of?(Integer) and 
	child >= @insert_at_index and @shifting_insert
    @chained_treebuilder.inactivate_child(child+1)
  else
    @chained_treebuilder.inactivate_child(child)
  end
end

#to_src(name = nil, nameHash = {}) ⇒ Object



223
224
225
226
227
228
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 223

def to_src(name = nil, nameHash = {})
  iai, di = @insert_at_index, @delete_indices
  ctb = @insert_at_index ? @chained_treebuilder : nil
  new_of_my_type(as_code(@indices.to_compact_src), @array_index,
   ctb, iai, as_code(di.to_compact_src), @append_element)
end