Class: ActiveKit::Export::Exporting

Inherits:
Bedrock::Bedrocking show all
Defined in:
lib/active_kit/export/exporting.rb

Instance Method Summary collapse

Methods inherited from Bedrock::Bedrocking

#initialize

Constructor Details

This class inherits a constructor from ActiveKit::Bedrock::Bedrocking

Instance Method Details

#headingsObject



4
5
6
# File 'lib/active_kit/export/exporting.rb', line 4

def headings
  @headings ||= @describer.fields.keys.flatten
end

#headings?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/active_kit/export/exporting.rb', line 8

def headings?
  headings.present?
end

#lines_for(record:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_kit/export/exporting.rb', line 12

def lines_for(record:)
  row_counter, column_counter = 1, 0

  @describer.fields.inject([[]]) do |rows, (heading, value)|
    if value.is_a? Proc
      rows[0].push(value.call(record))
      column_counter += 1
    elsif value.is_a?(Symbol) || value.is_a?(String)
      rows[0].push(record.public_send(value))
      column_counter += 1
    elsif value.is_a? Array
      deeprows = get_deeprows(record, heading, value, column_counter)
      deeprows.each do |deeprow|
        rows[row_counter] = deeprow
        row_counter += 1
      end

      column_count = get_column_count_for(value)
      column_count.times { |i| rows[0].push(nil) }
      column_counter += column_count
    else
      raise "Could not identify '#{value}' for '#{heading}'."
    end

    rows
  end
end