Class: CsvRowModel::DynamicColumnAttributeBase

Inherits:
AttributeBase show all
Includes:
DynamicColumnShared
Defined in:
lib/csv_row_model/internal/dynamic_column_attribute_base.rb

Instance Attribute Summary

Attributes inherited from AttributeBase

#column_name, #row_model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DynamicColumnShared

#column_index, #header_models, #header_models_context_key, #options

Methods included from ColumnShared

#context, #options

Methods inherited from AttributeBase

#formatted_value, #initialize, #row_model_class

Constructor Details

This class inherits a constructor from CsvRowModel::AttributeBase

Class Method Details

.define_process_cell(row_model_class, column_name, &block) ⇒ Object

define a method to process each cell of the attribute method process_cell = one cell attribute_method = many cells = [process_cell(), process_cell()...]


37
38
39
# File 'lib/csv_row_model/internal/dynamic_column_attribute_base.rb', line 37

def define_process_cell(row_model_class, column_name, &block)
  row_model_class.define_proxy_method(process_cell_method_name(column_name), &block)
end

.process_cell_method_name(column_name) ⇒ Object


30
31
32
# File 'lib/csv_row_model/internal/dynamic_column_attribute_base.rb', line 30

def process_cell_method_name(column_name)
  column_name.to_s.singularize.to_sym
end

Instance Method Details

#call_process_cell(*args) ⇒ Object (protected)

Calls the process_cell to return the value of a Attribute given the args


25
26
27
# File 'lib/csv_row_model/internal/dynamic_column_attribute_base.rb', line 25

def call_process_cell(*args)
  row_model.public_send(process_cell_method_name, *args)
end

#formatted_cellsObject


12
13
14
15
16
# File 'lib/csv_row_model/internal/dynamic_column_attribute_base.rb', line 12

def formatted_cells
  source_cells.map do |cell|
    row_model_class.format_cell(cell, column_name, row_model.context)
  end
end

#process_cell_method_nameObject (protected)


20
21
22
# File 'lib/csv_row_model/internal/dynamic_column_attribute_base.rb', line 20

def process_cell_method_name
  self.class.process_cell_method_name(column_name)
end

#valueObject


8
9
10
# File 'lib/csv_row_model/internal/dynamic_column_attribute_base.rb', line 8

def value
  @value ||= row_model_class.format_dynamic_column_cells(unformatted_value, column_name, row_model.context)
end