Class: Comptaline::Exporter

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

Instance Method Summary collapse

Constructor Details

#initializeExporter

Returns a new instance of Exporter.



3
4
5
# File 'lib/comptaline/exporter.rb', line 3

def initialize
  @entries_buffer = []
end

Instance Method Details

#add_customer(customer) ⇒ Object



27
28
29
# File 'lib/comptaline/exporter.rb', line 27

def add_customer(customer)
 add_line(customer)
end

#add_invoice(invoice) ⇒ Object



31
32
33
# File 'lib/comptaline/exporter.rb', line 31

def add_invoice(invoice)
  add_line(invoice)
end

#concat(entries) ⇒ Object



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

def concat(entries)
  @entries_buffer.concat(entries)
end

#flush!(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/comptaline/exporter.rb', line 15

def flush!(options = {})
  return "" unless @entries_buffer.size > 0

  csv = CSV.generate(col_sep: ";", row_sep: "\n", encoding: "iso-8859-1") do |csv|
    @entries_buffer.each do |entry|
      csv << encode(entry.to_a)
    end
  end
  Comptaline.client.send(csv) if options[:send] == true
  csv
end

#push(entry) ⇒ Object



11
12
13
# File 'lib/comptaline/exporter.rb', line 11

def push(entry)
  @entries_buffer.push(entry)
end