module CoinSync::Transaction::Amounts

Attributes

bought_amount[R]
bought_currency[R]
sold_amount[R]
sold_currency[R]

Public Instance Methods

crypto_amount() click to toggle source
# File lib/coinsync/transaction.rb, line 46
def crypto_amount
  case type
  when TYPE_PURCHASE then bought_amount
  when TYPE_SALE then sold_amount
  else raise "Operation not supported for crypto swap transactions"
  end
end
crypto_currency() click to toggle source
# File lib/coinsync/transaction.rb, line 62
def crypto_currency
  case type
  when TYPE_PURCHASE then bought_currency
  when TYPE_SALE then sold_currency
  else raise "Operation not supported for crypto swap transactions"
  end
end
fiat_amount() click to toggle source
# File lib/coinsync/transaction.rb, line 38
def fiat_amount
  case type
  when TYPE_PURCHASE then sold_amount
  when TYPE_SALE then bought_amount
  else raise "Operation not supported for crypto swap transactions"
  end
end
fiat_currency() click to toggle source
# File lib/coinsync/transaction.rb, line 54
def fiat_currency
  case type
  when TYPE_PURCHASE then sold_currency
  when TYPE_SALE then bought_currency
  else raise "Operation not supported for crypto swap transactions"
  end
end
price() click to toggle source
# File lib/coinsync/transaction.rb, line 70
def price
  fiat_amount / crypto_amount
end
purchase?() click to toggle source
# File lib/coinsync/transaction.rb, line 26
def purchase?
  type == TYPE_PURCHASE
end
sale?() click to toggle source
# File lib/coinsync/transaction.rb, line 30
def sale?
  type == TYPE_SALE
end
swap?() click to toggle source
# File lib/coinsync/transaction.rb, line 34
def swap?
  type == TYPE_SWAP
end
type() click to toggle source
# File lib/coinsync/transaction.rb, line 14
def type
  if bought_currency.crypto?
    if sold_currency.crypto?
      return TYPE_SWAP
    else
      return TYPE_PURCHASE
    end
  else
    return TYPE_SALE
  end
end