class ThousandIsland::Table
The Table
class can be used to set the definition of your table, such as format and headings. You then inject the data from your Builder
so that it can be rendered. You can declare a TableSettings
class that you wish to use, otherwise the default will be used. To set a Table
Setting class, add the following in your class body:
uses_style MyTableSettings
Attributes
table_settings_klass[W]
pdf[R]
table_options[RW]
Public Class Methods
new(pdf)
click to toggle source
# File lib/thousand_island/table.rb, line 28 def initialize(pdf) @pdf = pdf @table_options = {} end
table_settings_klass()
click to toggle source
# File lib/thousand_island/table.rb, line 19 def table_settings_klass @table_settings_klass ||= TableSettings end
uses_settings(klass)
click to toggle source
# File lib/thousand_island/table.rb, line 23 def uses_settings(klass) self.table_settings_klass = klass end
Public Instance Methods
body_rows()
click to toggle source
# File lib/thousand_island/table.rb, line 56 def body_rows @body_rows ||= [] end
body_rows=(row_array)
click to toggle source
# File lib/thousand_island/table.rb, line 51 def body_rows=(row_array) raise ArgumentError.new('table_rows must be an array') unless row_array.is_a?(Array) @body_rows = row_array end
draw(options={}) { |t| ... }
click to toggle source
# File lib/thousand_island/table.rb, line 37 def draw(options={}) @table_options = merged_options(options) table_options[:header] = prawn_header_setting pdf.table(table_data, options_for_prawn) do |t| t.row(0..num_header_rows - 1).font_style = table_options[:header_format][:font_style] unless header_rows.empty? t.row(0..num_header_rows - 1).align = table_options[:header_format][:align] unless header_rows.empty? t.row(-1..(0 - num_footer_rows)).font_style = :bold unless footer_rows.empty? yield(t) if block_given? end end
header_rows()
click to toggle source
# File lib/thousand_island/table.rb, line 65 def header_rows @header_rows ||= [] end
header_rows=(row_array)
click to toggle source
# File lib/thousand_island/table.rb, line 60 def header_rows=(row_array) raise ArgumentError.new('header_cells must be an array') unless row_array.is_a?(Array) @header_rows = row_array end
settings()
click to toggle source
# File lib/thousand_island/table.rb, line 33 def settings {} end
Private Instance Methods
deep_merger()
click to toggle source
# File lib/thousand_island/table.rb, line 114 def deep_merger @deep_merger ||= Utilities::DeepMerge::TableOptions end
merged_options(options={})
click to toggle source
# File lib/thousand_island/table.rb, line 106 def merged_options(options={}) deep_merger.merge_options(options, settings, table_settings.settings) end
num_header_rows()
click to toggle source
# File lib/thousand_island/table.rb, line 92 def num_header_rows header_rows.size end
options_for_prawn()
click to toggle source
# File lib/thousand_island/table.rb, line 102 def options_for_prawn table_options.select{ |k| [:cell_style, :header, :column_widths, :position, :width, :row_colors, ].include?(k)} end
prawn_header_setting()
click to toggle source
# File lib/thousand_island/table.rb, line 97 def prawn_header_setting return false if header_rows.empty? || table_options[:header_repeat] == false header_rows.size end
table_data()
click to toggle source
# File lib/thousand_island/table.rb, line 81 def table_data data = body_rows header_rows.reverse_each{ |row| data.unshift(row) } footer_rows.each{ |row| data << row } data end
table_settings()
click to toggle source
# File lib/thousand_island/table.rb, line 110 def table_settings @table_settings||= self.class.table_settings_klass.new(pdf, settings) end