Class: TnPDF::Table::Column
- Inherits:
-
Object
- Object
- TnPDF::Table::Column
- Defined in:
- lib/tn_pdf/table_column.rb
Overview
Represents a column of a table. Typically not used directly, but through Table#add_column and friends.
Instance Attribute Summary collapse
-
#column_width_type ⇒ Object
Returns the value of attribute column_width_type.
-
#header ⇒ String
readonly
Is a String that contains the column header.
-
#index ⇒ Object
Returns the value of attribute index.
-
#max_width ⇒ Object
Returns the value of attribute max_width.
-
#proc ⇒ #to_proc
(also: #to_proc)
readonly
Is an object that responds to to_proc, typically a Symbol or a Proc.
-
#style ⇒ Symbol, Hash
readonly
Defines how the formatting of the result will occur.
-
#width ⇒ Double, String
Defines the (visual) width of the column.
Instance Method Summary collapse
-
#initialize(arguments) ⇒ Column
constructor
Creates a new Column.
- #prawn_style ⇒ Object
- #value_for(object) ⇒ Object
Constructor Details
#initialize(arguments) ⇒ Column
Creates a new Column
The parameter has to be an Array in the form:
[header, procedure, style, width]
where:
- header (required)
-
Is a String that contains the column header
- procedure (required)
-
Is an object that responds to to_proc, typically a Symbol or a Proc. It represents the procedure used to extract the information from the object.
- style (optional)
-
Defines how the formatting of the result will occur. Typically used for formatting currencies, numbers etc, but can be anything defined on Configuration, the YAML Configuration file or a Hash that contains (at least) the :format key. It defaults to the :text style.
- width (optional)
-
Defines the (visual) width of the column. May be defined in PDF points (1/72 inch), a String “in” the cm or mm units, or a String representing a percentage.
It is important to note that, in the case of a percentage-based column, it represents a percentage of the page on which the table will be rendered, not of the table.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tn_pdf/table_column.rb', line 76 def initialize(arguments) raise ArgumentError unless valid_column_args?(arguments) @header = arguments[0].to_s @proc = arguments[1].to_proc @style = Column.style_for(arguments[2]) @width = Configuration.perform_conversions arguments[3] if @width.nil? column_width_type = :generated end end |
Instance Attribute Details
#column_width_type ⇒ Object
Returns the value of attribute column_width_type.
57 58 59 |
# File 'lib/tn_pdf/table_column.rb', line 57 def column_width_type @column_width_type end |
#header ⇒ String (readonly)
Is a String that contains the column header
8 9 10 |
# File 'lib/tn_pdf/table_column.rb', line 8 def header @header end |
#index ⇒ Object
Returns the value of attribute index.
121 122 123 |
# File 'lib/tn_pdf/table_column.rb', line 121 def index @index end |
#max_width ⇒ Object
Returns the value of attribute max_width.
121 122 123 |
# File 'lib/tn_pdf/table_column.rb', line 121 def max_width @max_width end |
#proc ⇒ #to_proc (readonly) Also known as: to_proc
Is an object that responds to to_proc, typically a Symbol or a Proc. It represents the procedure used to extract the information from the object.
21 22 23 |
# File 'lib/tn_pdf/table_column.rb', line 21 def proc @proc end |
#style ⇒ Symbol, Hash (readonly)
Defines how the formatting of the result will occur. Typically used for formatting currencies, numbers etc, but can be anything defined on Configuration, the YAML Configuration file or a Hash that contains (at least) the :format key. It defaults to the :text style.
35 36 37 |
# File 'lib/tn_pdf/table_column.rb', line 35 def style @style end |
#width ⇒ Double, String
Defines the (visual) width of the column. May be defined in PDF points (1/72 inch), a String “in” the cm or mm units, or a String representing a percentage.
It is important to note that, in the case of a percentage-based column, it represents a percentage of the page on which the table will be rendered, not of the table.
53 54 55 |
# File 'lib/tn_pdf/table_column.rb', line 53 def width @width end |
Instance Method Details
#prawn_style ⇒ Object
92 93 94 |
# File 'lib/tn_pdf/table_column.rb', line 92 def prawn_style style.reject { |k, v| [:format, :decimal].include? k } end |
#value_for(object) ⇒ Object
87 88 89 90 |
# File 'lib/tn_pdf/table_column.rb', line 87 def value_for(object) value = @proc.call(object) Column.format_value(value, style) end |