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
36 37 38 39 |
# File 'lib/csv_row_model/export/attributes.rb', line 36 def column(column_name, ={}) super define_attribute_method(column_name) end |
.define_attribute_method(column_name) ⇒ Object
Define default attribute method for a column
43 44 45 46 47 |
# File 'lib/csv_row_model/export/attributes.rb', line 43 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
52 53 54 |
# File 'lib/csv_row_model/export/attributes.rb', line 52 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 26 27 |
# File 'lib/csv_row_model/export/attributes.rb', line 18 def formatted_attribute(column_name) return public_send(column_name) if self.class.is_dynamic_column?(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)
30 31 32 |
# File 'lib/csv_row_model/export/attributes.rb', line 30 def formatted_attributes_from_column_names(column_names) array_to_block_hash(column_names) { |column_name| formatted_attribute(column_name) } end |