Class: CoinSync::Outputs::Raw

Inherits:
Base
  • Object
show all
Defined in:
lib/coinsync/outputs/raw.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, register_output, #requires_currency_conversion?

Constructor Details

This class inherits a constructor from CoinSync::Outputs::Base

Instance Method Details

#headersObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/coinsync/outputs/raw.rb', line 20

def headers
  [
    'Exchange',
    'Date',
    'Bought amount',
    'Bought currency',
    'Sold amount',
    'Sold currency'
  ]
end

#process_transactions(transactions, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/coinsync/outputs/raw.rb', line 10

def process_transactions(transactions, *args)
  CSV.open(@target_file, 'w', col_sep: @config.column_separator) do |csv|
    csv << headers

    transactions.each do |tx|
      csv << transaction_to_csv(tx)
    end
  end
end

#transaction_to_csv(tx) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/coinsync/outputs/raw.rb', line 31

def transaction_to_csv(tx)
  [
    tx.exchange,
    @formatter.format_time(tx.time),
    tx.bought_currency.crypto? ?
      @formatter.format_crypto(tx.bought_amount) : @formatter.format_fiat(tx.bought_amount),
    tx.bought_currency.code,
    tx.sold_currency.crypto? ?
      @formatter.format_crypto(tx.sold_amount) : @formatter.format_fiat(tx.sold_amount),
    tx.sold_currency.code
  ]
end