Module: Cartos::Cashbase
- Defined in:
- lib/cartos/cashbase.rb
Defined Under Namespace
Classes: Collection, Entry
Class Method Summary collapse
- .importer=(importer) ⇒ Object
-
.load ⇒ Object
def self.load(data).
Class Method Details
.importer=(importer) ⇒ Object
4 5 6 |
# File 'lib/cartos/cashbase.rb', line 4 def self.importer=(importer) @importer = importer end |
.load ⇒ Object
def self.load(data)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cartos/cashbase.rb', line 9 def self.load data_array = CSV.parse @importer.import data_array.shift #Remove header row entries = data_array.inject([]) do |acc, row| if row[4].force_encoding('UTF-8') == Cartos.config.cashbasehq.account_name entry = Cartos::Cashbase::Entry.new date_string = row[0].split("-") entry.date = Time.new date_string[0], date_string[1], date_string[2] entry.amount = row[1].to_f entry.category = row[2] entry.description = row[3] acc << entry else acc end end collection = Collection.new collection.elements = entries collection end |