Module: CsvRowModel::Export::Base

Extended by:
ActiveSupport::Concern
Included in:
CsvRowModel::Export
Defined in:
lib/csv_row_model/export/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/csv_row_model/export/base.rb', line 7

def context
  @context
end

#source_modelObject (readonly)

Returns the value of attribute source_model.



7
8
9
# File 'lib/csv_row_model/export/base.rb', line 7

def source_model
  @source_model
end

Class Method Details

.setup(csv, context = {}, with_headers: true) ⇒ Object



28
29
30
# File 'lib/csv_row_model/export/base.rb', line 28

def setup(csv, context={}, with_headers: true)
  csv << headers(context) if with_headers
end

Instance Method Details

#initialize(source_model, context = {}) ⇒ Object

Parameters:

  • source_model (Model)

    object to export to CSV

  • context (Hash) (defaults to: {})


13
14
15
16
# File 'lib/csv_row_model/export/base.rb', line 13

def initialize(source_model, context={})
  @source_model = source_model
  @context      = OpenStruct.new(context)
end

#to_rowArray

Returns an array of public_send(column_name) of the CSV model.

Returns:

  • (Array)

    an array of public_send(column_name) of the CSV model



23
24
25
# File 'lib/csv_row_model/export/base.rb', line 23

def to_row
  formatted_attributes.values
end

#to_rowsObject



18
19
20
# File 'lib/csv_row_model/export/base.rb', line 18

def to_rows
  [to_row]
end