Module: CsvRowModel::Export::Attributes
- Extended by:
- ActiveSupport::Concern
- Includes:
- Model::Comparison
- Included in:
- CsvRowModel::Export
- Defined in:
- lib/csv_row_model/export/attributes.rb
Class Method Summary collapse
-
.column(column_name, options = {}) ⇒ Object
See Model#column.
-
.define_attribute_method(column_name) ⇒ Object
Define default attribute method for a column.
-
.format_cell(cell, column_name, column_index, context = {}) ⇒ Object
Safe to override.
Instance Method Summary collapse
- #formatted_attribute(column_name) ⇒ Object
-
#formatted_attributes ⇒ Hash
A map of
column_name => self.class.format_cell(public_send(column_name)). - #formatted_attributes_from_column_names(column_names) ⇒ Object protected
Methods included from Model::Comparison
Class Method Details
.column(column_name, options = {}) ⇒ Object
See Model#column
34 35 36 37 |
# File 'lib/csv_row_model/export/attributes.rb', line 34 def column(column_name, ={}) super define_attribute_method(column_name) end |
.define_attribute_method(column_name) ⇒ Object
Define default attribute method for a column
41 42 43 44 45 |
# File 'lib/csv_row_model/export/attributes.rb', line 41 def define_attribute_method(column_name) define_method(column_name) do source_model.public_send(column_name) end end |
.format_cell(cell, column_name, column_index, context = {}) ⇒ Object
Safe to override. Method applied to each cell by default
50 51 52 |
# File 'lib/csv_row_model/export/attributes.rb', line 50 def format_cell(cell, column_name, column_index, context={}) cell end |
Instance Method Details
#formatted_attribute(column_name) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/csv_row_model/export/attributes.rb', line 18 def formatted_attribute(column_name) self.class.format_cell( public_send(column_name), column_name, self.class.index(column_name), context ) end |
#formatted_attributes ⇒ Hash
Returns a map of column_name => self.class.format_cell(public_send(column_name)).
14 15 16 |
# File 'lib/csv_row_model/export/attributes.rb', line 14 def formatted_attributes formatted_attributes_from_column_names self.class.column_names end |
#formatted_attributes_from_column_names(column_names) ⇒ Object (protected)
28 29 30 |
# File 'lib/csv_row_model/export/attributes.rb', line 28 def formatted_attributes_from_column_names(column_names) array_to_block_hash(column_names) { |column_name| formatted_attribute(column_name) } end |