class CoinSync::Outputs::Summary
Public Instance Methods
process_transactions(transactions, *args)
click to toggle source
# File lib/coinsync/outputs/summary.rb, line 16 def process_transactions(transactions, *args) totals = Hash.new { BigDecimal(0) } transactions.each do |tx| break if args.first.to_i > 0 && tx.time.year >= args.first.to_i if tx.bought_currency.crypto? amount = totals[tx.bought_currency] totals[tx.bought_currency] = amount + tx.bought_amount end if tx.sold_currency.crypto? amount = totals[tx.sold_currency] if amount >= tx.sold_amount totals[tx.sold_currency] = amount - tx.sold_amount else raise "Summary: couldn't sell #{@formatter.format_crypto(tx.sold_amount)} #{tx.sold_currency.code} " + "if only #{@formatter.format_crypto(amount)} was owned" end end end rows = totals.map do |currency, amount| [ currency.code, @formatter.format_crypto(amount) ] end printer = TablePrinter.new printer.print_table(['Coin', 'Amount'], rows, alignment: [:ljust, :rjust]) end
requires_currency_conversion?()
click to toggle source
# File lib/coinsync/outputs/summary.rb, line 12 def requires_currency_conversion? false end