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

Instance Method Summary collapse

Class Method Details

.column(column_name, options = {}) ⇒ Object

See Model#column



30
31
32
33
# File 'lib/csv_row_model/export/attributes.rb', line 30

def column(column_name, options={})
  super
  define_attribute_method(column_name)
end

.define_attribute_method(column_name) ⇒ Object

Define default attribute method for a column

Parameters:

  • column_name (Symbol)

    the cell's column_name



37
38
39
40
41
# File 'lib/csv_row_model/export/attributes.rb', line 37

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) ⇒ Object

Safe to override. Method applied to each cell by default

Parameters:

  • cell (Object)

    the cell's value



46
47
48
# File 'lib/csv_row_model/export/attributes.rb', line 46

def format_cell(cell, column_name, column_index)
  cell
end

Instance Method Details

#formatted_attribute(column_name) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/csv_row_model/export/attributes.rb', line 15

def formatted_attribute(column_name)
  self.class.format_cell(
    public_send(column_name),
    column_name,
    self.class.index(column_name)
  )
end

#formatted_attributesHash

Returns a map of column_name => self.class.format_cell()public_send(column_name)).

Returns:

  • (Hash)

    a map of column_name => self.class.format_cell()public_send(column_name))



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)



24
25
26
# File 'lib/csv_row_model/export/attributes.rb', line 24

def formatted_attributes_from_column_names(column_names)
  array_to_block_hash(column_names) { |column_name| formatted_attribute(column_name) }
end