module TablePrint::RowRecursion
Attributes
children[RW]
parent[RW]
Public Class Methods
new()
click to toggle source
# File lib/table_print/row_group.rb, line 7 def initialize @children = [] @columns = {} end
Public Instance Methods
add_child(child)
click to toggle source
# File lib/table_print/row_group.rb, line 12 def add_child(child) @children << child child.parent = self end
add_children(children)
click to toggle source
# File lib/table_print/row_group.rb, line 23 def add_children(children) @children.concat children children.each { |c| c.parent = self } self end
add_formatter(name, formatter)
click to toggle source
# File lib/table_print/row_group.rb, line 82 def add_formatter(name, formatter) return unless column_for(name) column_for(name).add_formatter(formatter) end
child_count()
click to toggle source
# File lib/table_print/row_group.rb, line 29 def child_count @children.length end
column_count()
click to toggle source
# File lib/table_print/row_group.rb, line 44 def column_count return parent.column_count if parent @columns.size end
column_for(name)
click to toggle source
# File lib/table_print/row_group.rb, line 49 def column_for(name) return parent.column_for(name) if parent column = @columns[name.to_s] ||= Column.new(:name => name) # assign the data sets to the column before we return it # do this as late as possible, since new rows could be added at any time column.data ||= raw_column_data(column.name) column end
columns()
click to toggle source
# File lib/table_print/row_group.rb, line 38 def columns return parent.columns if parent raw_column_names.collect{|k, v| column_for(k)} end
header()
click to toggle source
# File lib/table_print/row_group.rb, line 70 def header padded_names = columns.collect do |column| f = FixedWidthFormatter.new(column.width) f.format(column.name) end header_string = padded_names.join(" #{TablePrint::Config.separator} ") header_string.upcase! if TablePrint::Config.capitalize_headers header_string end
horizontal_separator()
click to toggle source
# File lib/table_print/row_group.rb, line 64 def horizontal_separator columns.collect do |column| '-' * column.width end.join("-#{TablePrint::Config.separator}-") end
insert_children(i, children)
click to toggle source
# File lib/table_print/row_group.rb, line 17 def insert_children(i, children) @children.insert(i, children).flatten! children.each {|c| c.parent = self } self end
set_column(column)
click to toggle source
# File lib/table_print/row_group.rb, line 33 def set_column(column) return parent.set_column(column) if parent @columns[column.name.to_s] = column end
width()
click to toggle source
# File lib/table_print/row_group.rb, line 59 def width return parent.width if parent columns.collect(&:width).inject(&:+) + (columns.length - 1) * 3 # add (n-1)*3 for the 3-character separator end