Module: TablePrint::RowRecursion

Included in:
Row, RowGroup
Defined in:
lib/table_print/row_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/table_print/row_group.rb', line 5

def children
  @children
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/table_print/row_group.rb', line 4

def parent
  @parent
end

Instance Method Details

#add_child(child) ⇒ Object



12
13
14
15
# File 'lib/table_print/row_group.rb', line 12

def add_child(child)
  @children << child
  child.parent = self
end

#add_children(children) ⇒ Object



23
24
25
26
27
# 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) ⇒ Object



82
83
84
85
# 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_countObject



29
30
31
# File 'lib/table_print/row_group.rb', line 29

def child_count
  @children.length
end

#column_countObject



44
45
46
47
# File 'lib/table_print/row_group.rb', line 44

def column_count
  return parent.column_count if parent
  @columns.size
end

#column_for(name) ⇒ Object



49
50
51
52
53
54
55
56
57
# 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

#columnsObject



38
39
40
41
42
# 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

#headerObject



70
71
72
73
74
75
76
77
78
79
80
# 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_separatorObject



64
65
66
67
68
# File 'lib/table_print/row_group.rb', line 64

def horizontal_separator
  columns.collect do |column|
    '-' * column.width
  end.join("-#{TablePrint::Config.separator}-")
end

#initializeObject



7
8
9
10
# File 'lib/table_print/row_group.rb', line 7

def initialize
  @children = []
  @columns = {}
end

#insert_children(i, children) ⇒ Object



17
18
19
20
21
# 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) ⇒ Object



33
34
35
36
# 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

#widthObject



59
60
61
62
# 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