Class: ThousandIsland::Table
- Inherits:
-
Object
- Object
- ThousandIsland::Table
- Defined in:
- lib/thousand_island/table.rb
Overview
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
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#pdf ⇒ Object
readonly
Returns the value of attribute pdf.
-
#table_options ⇒ Object
Returns the value of attribute table_options.
Class Method Summary collapse
Instance Method Summary collapse
- #body_rows ⇒ Object
- #body_rows=(row_array) ⇒ Object
- #draw(options = {}) ⇒ Object
- #footer_rows ⇒ Object
- #footer_rows=(row_array) ⇒ Object
- #header_rows ⇒ Object
- #header_rows=(row_array) ⇒ Object
-
#initialize(pdf) ⇒ Table
constructor
A new instance of Table.
- #settings ⇒ Object
Constructor Details
#initialize(pdf) ⇒ Table
Returns a new instance of Table.
28 29 30 31 |
# File 'lib/thousand_island/table.rb', line 28 def initialize(pdf) @pdf = pdf = {} end |
Class Attribute Details
.table_settings_klass ⇒ Object
19 20 21 |
# File 'lib/thousand_island/table.rb', line 19 def table_settings_klass @table_settings_klass ||= TableSettings end |
Instance Attribute Details
#pdf ⇒ Object (readonly)
Returns the value of attribute pdf.
13 14 15 |
# File 'lib/thousand_island/table.rb', line 13 def pdf @pdf end |
#table_options ⇒ Object
Returns the value of attribute table_options.
14 15 16 |
# File 'lib/thousand_island/table.rb', line 14 def end |
Class Method Details
.uses_settings(klass) ⇒ Object
23 24 25 |
# File 'lib/thousand_island/table.rb', line 23 def uses_settings(klass) self.table_settings_klass = klass end |
Instance Method Details
#body_rows ⇒ Object
56 57 58 |
# File 'lib/thousand_island/table.rb', line 56 def body_rows @body_rows ||= [] end |
#body_rows=(row_array) ⇒ Object
51 52 53 54 |
# 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 = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/thousand_island/table.rb', line 37 def draw(={}) = () [:header] = prawn_header_setting pdf.table(table_data, ) do |t| t.row(0..num_header_rows - 1).font_style = [:header_format][:font_style] unless header_rows.empty? t.row(0..num_header_rows - 1).align = [:header_format][:align] unless header_rows.empty? t.row(-1..(0 - )).font_style = :bold unless .empty? yield(t) if block_given? end end |
#footer_rows ⇒ Object
74 75 76 |
# File 'lib/thousand_island/table.rb', line 74 def ||= [] end |
#footer_rows=(row_array) ⇒ Object
69 70 71 72 |
# File 'lib/thousand_island/table.rb', line 69 def (row_array) raise ArgumentError.new('footer_rows must be an array') unless row_array.is_a?(Array) = row_array end |
#header_rows ⇒ Object
65 66 67 |
# File 'lib/thousand_island/table.rb', line 65 def header_rows @header_rows ||= [] end |
#header_rows=(row_array) ⇒ Object
60 61 62 63 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/thousand_island/table.rb', line 33 def settings {} end |