Module: CsvRowModel::Export::Attributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- CsvRowModel::Export
- Defined in:
- lib/csv_row_model/export/attributes.rb
Class Method Summary collapse
-
.column(column_name, options = {}) ⇒ Object
protected
See Model#column.
-
.define_attribute_method(column_name) ⇒ Object
protected
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
Class Method Details
.column(column_name, options = {}) ⇒ Object (protected)
See Model#column
41 42 43 44 |
# File 'lib/csv_row_model/export/attributes.rb', line 41 def column(column_name, ={}) super define_attribute_method(column_name) end |
.define_attribute_method(column_name) ⇒ Object (protected)
Define default attribute method for a column
48 49 50 51 |
# File 'lib/csv_row_model/export/attributes.rb', line 48 def define_attribute_method(column_name) return if method_defined? column_name define_method(column_name) { source_model.public_send(column_name) } end |
.format_cell(cell, column_name, column_index, context = {}) ⇒ Object
Safe to override. Method applied to each cell by default
35 36 37 |
# File 'lib/csv_row_model/export/attributes.rb', line 35 def format_cell(cell, column_name, column_index, context={}) cell end |
Instance Method Details
#formatted_attribute(column_name) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/csv_row_model/export/attributes.rb', line 15 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
11 12 13 |
# File 'lib/csv_row_model/export/attributes.rb', line 11 def formatted_attributes formatted_attributes_from_column_names self.class.column_names end |
#formatted_attributes_from_column_names(column_names) ⇒ Object (protected)
27 28 29 |
# File 'lib/csv_row_model/export/attributes.rb', line 27 def formatted_attributes_from_column_names(column_names) array_to_block_hash(column_names) { |column_name| formatted_attribute(column_name) } end |