Class: Lite::Report::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/lite/report/exporter.rb

Defined Under Namespace

Classes: NotImplementedError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records) ⇒ Exporter

Returns a new instance of Exporter.



9
10
11
# File 'lib/lite/report/exporter.rb', line 9

def initialize(records)
  @records = records
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



7
8
9
# File 'lib/lite/report/exporter.rb', line 7

def records
  @records
end

Class Method Details

.call(records) ⇒ Object



15
16
17
18
# File 'lib/lite/report/exporter.rb', line 15

def call(records)
  instance = new(records)
  instance.call
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lite/report/exporter.rb', line 22

def call
  results = []

  if records.respond_to?(:find_each)
    records.find_each { |record| results << serialize(record) }
  elsif records.respond_to?(:each)
    records.each { |record| results << serialize(record) }
  else
    results << serialize(records)
  end

  results
end