class CoinSync::CryptoClassifier

Constants

MAX_INDEX

Public Class Methods

new(config) click to toggle source
# File lib/coinsync/crypto_classifier.rb, line 7
def initialize(config)
  @config = config
  @base_currencies = config.base_cryptocurrencies.map { |c| CryptoCurrency.new(c) }
end

Public Instance Methods

is_purchase?(transaction) click to toggle source
# File lib/coinsync/crypto_classifier.rb, line 12
def is_purchase?(transaction)
  bought_index = @base_currencies.index(transaction.bought_currency) || MAX_INDEX
  sold_index = @base_currencies.index(transaction.sold_currency) || MAX_INDEX

  if bought_index < sold_index
    false
  elsif bought_index > sold_index
    true
  else
    raise "Couldn't determine which cryptocurrency is the base one: #{transaction.bought_currency.code} vs " +
      "#{transaction.sold_currency.code}. Use the `base_cryptocurrencies` setting to explicitly choose " +
      "base cryptocurrencies."
  end
end