module CsvRowModel::Export::Attributes
Public Instance Methods
formatted_attribute(column_name)
click to toggle source
# 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()
click to toggle source
@return [Hash] a map of ‘column_name => self.class.format_cell(public_send(column_name))`
# File lib/csv_row_model/export/attributes.rb, line 11 def formatted_attributes formatted_attributes_from_column_names self.class.column_names end
Protected Instance Methods
column(column_name, options={})
click to toggle source
See {Model#column}
Calls superclass method
# File lib/csv_row_model/export/attributes.rb, line 41 def column(column_name, options={}) super define_attribute_method(column_name) end
define_attribute_method(column_name)
click to toggle source
Define default attribute method for a column @param column_name [Symbol] the cell’s column_name
# 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={})
click to toggle source
Safe to override. Method applied to each cell by default
@param cell [Object] the cell’s value
# File lib/csv_row_model/export/attributes.rb, line 35 def format_cell(cell, column_name, column_index, context={}) cell end
formatted_attributes_from_column_names(column_names)
click to toggle source
# 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