Class: CoinSync::Importers::Default
- Defined in:
- lib/coinsync/importers/default.rb
Defined Under Namespace
Classes: HistoryEntry
Instance Method Summary collapse
-
#initialize(config, params = {}) ⇒ Default
constructor
A new instance of Default.
- #read_transaction_list(source) ⇒ Object
Methods inherited from Base
#can_build?, register_commands, register_importer, registered_commands
Constructor Details
Instance Method Details
#read_transaction_list(source) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/coinsync/importers/default.rb', line 25 def read_transaction_list(source) csv = CSV.new(source, col_sep: @config.column_separator) transactions = [] csv.each do |line| next if line.empty? next if line.all? { |f| f.to_s.strip == '' } next if line[0] == 'Lp' entry = parse_line(line) if entry.type.downcase == Transaction::TYPE_PURCHASE.to_s transactions << Transaction.new( exchange: entry.exchange, bought_currency: entry.asset, sold_currency: entry.currency, time: entry.date, bought_amount: entry.amount, sold_amount: entry.total ) elsif entry.type.downcase == Transaction::TYPE_SALE.to_s transactions << Transaction.new( exchange: entry.exchange, bought_currency: entry.currency, sold_currency: entry.asset, time: entry.date, bought_amount: entry.total, sold_amount: entry.amount ) else raise "Default importer error: unexpected entry type '#{entry.type}'" end end transactions end |