Class: Csvbuilder::DynamicColumnAttributeBase

Inherits:
AttributeBase
  • Object
show all
Includes:
DynamicColumnShared
Defined in:
lib/csvbuilder/dynamic/columns/core/internal/dynamic_column_attribute_base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DynamicColumnShared

#column_index, #header_models, #header_models_context_key, #options

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()…]



51
52
53
# File 'lib/csvbuilder/dynamic/columns/core/internal/dynamic_column_attribute_base.rb', line 51

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



44
45
46
# File 'lib/csvbuilder/dynamic/columns/core/internal/dynamic_column_attribute_base.rb', line 44

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

Instance Method Details

#formatted_cellsArray

The source_cells is meant to be implemented in the concret class

Returns:

  • (Array)

    Array of values



18
19
20
21
22
# File 'lib/csvbuilder/dynamic/columns/core/internal/dynamic_column_attribute_base.rb', line 18

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

#source_cellsObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/csvbuilder/dynamic/columns/core/internal/dynamic_column_attribute_base.rb', line 24

def source_cells
  raise NotImplementedError
end

#unformatted_valueObject

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/csvbuilder/dynamic/columns/core/internal/dynamic_column_attribute_base.rb', line 28

def unformatted_value
  raise NotImplementedError
end

#valueArray

The value is the collection of cell’s values

Returns:

  • (Array)

    Array of values



12
13
14
# File 'lib/csvbuilder/dynamic/columns/core/internal/dynamic_column_attribute_base.rb', line 12

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