Class: CoinSync::CryptoClassifier
- Inherits:
-
Object
- Object
- CoinSync::CryptoClassifier
- Defined in:
- lib/coinsync/crypto_classifier.rb
Constant Summary collapse
- MAX_INDEX =
1_000_000
Instance Method Summary collapse
-
#initialize(config) ⇒ CryptoClassifier
constructor
A new instance of CryptoClassifier.
- #is_purchase?(transaction) ⇒ Boolean
Constructor Details
#initialize(config) ⇒ CryptoClassifier
Returns a new instance of CryptoClassifier.
7 8 9 10 |
# File 'lib/coinsync/crypto_classifier.rb', line 7 def initialize(config) @config = config @base_currencies = config.base_cryptocurrencies.map { |c| CryptoCurrency.new(c) } end |
Instance Method Details
#is_purchase?(transaction) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |