Class: ActiveWarehouse::Aggregate::DwarfPrinter

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

Overview

Dwarf support class that prints a representation of the Dwarf

Class Method Summary collapse

Class Method Details

.all_cell_to_string(cell) ⇒ Object



29
30
31
# File 'lib/active_warehouse/aggregate/dwarf_printer.rb', line 29

def self.all_cell_to_string(cell)
  cell ? (cell.value ? cell.value.inspect : '') : ''
end

.cell_to_string(cell) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/active_warehouse/aggregate/dwarf_printer.rb', line 20

def self.cell_to_string(cell)
  # a new String object must be created here, otherwise to_s returns a reference
  # to the same String object each time and thus the value will be appended each time
  # which is not what I want
  s = String.new(cell.key.to_s)
  s << " #{cell.value.join(',')}" if cell.node.leaf?
  s
end

Print the specified node at the given depth.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_warehouse/aggregate/dwarf_printer.rb', line 6

def self.print_node(node, depth=0, recurse=true)
  #puts "printing node #{node.index}"
  cells = node.cells.collect { |c| cell_to_string(c)}.join('|')

  parent_node = node.parent ? "#{cell_to_string(node.parent)}:" : ''
  puts "#{node.index}=#{' '*depth}#{parent_node}[#{cells}|#{all_cell_to_string(node.all_cell)}]"
  if !node.leaf?
    print_node(node.all_cell.child, depth + 1, false) if node.all_cell
  end
  if recurse
    node.children.each { |child| print_node(child, depth+1) }
  end
end