Class: ActiveWarehouse::Aggregate::DwarfAggregate::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/active_warehouse/aggregate/dwarf_aggregate.rb

Constant Summary collapse

@@sequence =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = nil, parent_cell = nil) ⇒ Node

Initialize the node with a cell that has the given key



304
305
306
307
308
309
310
311
312
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 304

def initialize(key=nil, parent_cell=nil)
  @closed = false
  @processed = false
  @parent = parent_cell
  @parent.child = self if @parent
  @index = @@sequence += 1
  #puts "creating node #{@index} with parent: #{@parent}"
  add_cell(Cell.new(key)) if key
end

Instance Attribute Details

#all_cellObject

A special cell which will hold either a reference to a sub node or the aggregate values for all of the values in the node’s cells



284
285
286
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 284

def all_cell
  @all_cell
end

#closedObject

Set the true if the node is closed



290
291
292
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 290

def closed
  @closed
end

#indexObject (readonly)

Reader accessor for the node index, a sequential number identifying order of creation



299
300
301
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 299

def index
  @index
end

#leafObject

Set to true if this node is a leaf node



296
297
298
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 296

def leaf
  @leaf
end

#parentObject

The parent cell or nil



287
288
289
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 287

def parent
  @parent
end

#processedObject

Set to true if the node has been processed



293
294
295
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 293

def processed
  @processed
end

Instance Method Details

#add_cell(cell) ⇒ Object



353
354
355
356
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 353

def add_cell(cell)
  cell.node = self
  cells << cell
end

#cellsObject

Return an array of cells for the node



315
316
317
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 315

def cells
  @cells ||= []
end

#child(key) ⇒ Object



330
331
332
333
334
335
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 330

def child(key)
  cells.each do |cell|
    return cell.child if cell.key == key
  end
  return nil
end

#childrenObject



337
338
339
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 337

def children
  cells.collect { |cell| cell.child }.compact
end

#closed?Boolean

Returns:

  • (Boolean)


341
342
343
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 341

def closed?
  closed
end

#has_cell_with_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


323
324
325
326
327
328
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 323

def has_cell_with_key?(key)
  cells.each do |cell|
    return true if cell.key == key
  end
  return false
end

#keysObject



319
320
321
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 319

def keys
  cells.collect { |cell| cell.key }
end

#leaf?Boolean

Returns:

  • (Boolean)


349
350
351
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 349

def leaf?
  leaf
end

#processed?Boolean

Returns:

  • (Boolean)


345
346
347
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 345

def processed?
  processed
end

#to_sObject



363
364
365
# File 'lib/active_warehouse/aggregate/dwarf_aggregate.rb', line 363

def to_s
  index.to_s
end