Class: CoinSync::Importers::BitBay20::HistoryEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/coinsync/importers/bitbay20.rb

Constant Summary collapse

POLISH_TIMEZONE =
TZInfo::Timezone.get('Europe/Warsaw')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ HistoryEntry

Returns a new instance of HistoryEntry.



30
31
32
33
34
35
36
37
38
39
# File 'lib/coinsync/importers/bitbay20.rb', line 30

def initialize(line)
  @date = POLISH_TIMEZONE.local_to_utc(Time.parse(line[0])) unless line[0] == '-'
  @accounting_date = POLISH_TIMEZONE.local_to_utc(Time.parse(line[1])) unless line[1] == '-'

  @type = line[2]

  amount, currency = line[3].split(' ')
  @amount = BigDecimal.new(amount.gsub(/,/, ''))
  @currency = parse_currency(currency)
end

Instance Attribute Details

#accounting_dateObject

Returns the value of attribute accounting_date.



26
27
28
# File 'lib/coinsync/importers/bitbay20.rb', line 26

def accounting_date
  @accounting_date
end

#amountObject

Returns the value of attribute amount.



26
27
28
# File 'lib/coinsync/importers/bitbay20.rb', line 26

def amount
  @amount
end

#currencyObject

Returns the value of attribute currency.



26
27
28
# File 'lib/coinsync/importers/bitbay20.rb', line 26

def currency
  @currency
end

#dateObject

Returns the value of attribute date.



26
27
28
# File 'lib/coinsync/importers/bitbay20.rb', line 26

def date
  @date
end

#typeObject

Returns the value of attribute type.



26
27
28
# File 'lib/coinsync/importers/bitbay20.rb', line 26

def type
  @type
end

Instance Method Details

#crypto?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/coinsync/importers/bitbay20.rb', line 41

def crypto?
  @currency.crypto?
end

#fiat?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/coinsync/importers/bitbay20.rb', line 45

def fiat?
  @currency.fiat?
end

#parse_currency(code) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/coinsync/importers/bitbay20.rb', line 49

def parse_currency(code)
  case code
  when 'BTC' then CryptoCurrency.new('BTC')
  when 'ETH' then CryptoCurrency.new('ETH')
  when 'LSK' then CryptoCurrency.new('LSK')
  when 'LTC' then CryptoCurrency.new('LTC')
  when 'PLN' then FiatCurrency.new('PLN')
  else raise "Unknown currency: #{code}"
  end
end