Class: Abbu::Exporters::CsvExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/abbu/exporters/csv_exporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(contacts) ⇒ CsvExporter

Returns a new instance of CsvExporter.



9
10
11
# File 'lib/abbu/exporters/csv_exporter.rb', line 9

def initialize(contacts)
  @contacts = contacts
end

Instance Method Details

#to_file(path) ⇒ Object



13
14
15
16
17
18
# File 'lib/abbu/exporters/csv_exporter.rb', line 13

def to_file(path)
  CSV.open(path, 'w') do |csv|
    csv << headers
    @contacts.each { |c| csv << row(c) }
  end
end

#to_stdoutObject



20
21
22
23
24
25
# File 'lib/abbu/exporters/csv_exporter.rb', line 20

def to_stdout
  puts(CSV.generate do |csv|
    csv << headers
    @contacts.each { |c| csv << row(c) }
  end)
end