Class: Comptaline::Exporter
- Inherits:
-
Object
- Object
- Comptaline::Exporter
- Defined in:
- lib/comptaline/exporter.rb
Instance Method Summary collapse
- #add_customer(customer) ⇒ Object
- #add_invoice(invoice) ⇒ Object
- #concat(entries) ⇒ Object
- #flush!(options = {}) ⇒ Object
-
#initialize ⇒ Exporter
constructor
A new instance of Exporter.
- #push(entry) ⇒ Object
Constructor Details
#initialize ⇒ Exporter
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!( = {}) 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 [: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 |