Module: CoinSync::Transaction::Amounts

Included in:
CoinSync::Transaction, ConvertedAmounts
Defined in:
lib/coinsync/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bought_amountObject (readonly)

Returns the value of attribute bought_amount.



12
13
14
# File 'lib/coinsync/transaction.rb', line 12

def bought_amount
  @bought_amount
end

#bought_currencyObject (readonly)

Returns the value of attribute bought_currency.



12
13
14
# File 'lib/coinsync/transaction.rb', line 12

def bought_currency
  @bought_currency
end

#sold_amountObject (readonly)

Returns the value of attribute sold_amount.



12
13
14
# File 'lib/coinsync/transaction.rb', line 12

def sold_amount
  @sold_amount
end

#sold_currencyObject (readonly)

Returns the value of attribute sold_currency.



12
13
14
# File 'lib/coinsync/transaction.rb', line 12

def sold_currency
  @sold_currency
end

Instance Method Details

#crypto_amountObject



46
47
48
49
50
51
52
# 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_currencyObject



62
63
64
65
66
67
68
# 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_amountObject



38
39
40
41
42
43
44
# 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_currencyObject



54
55
56
57
58
59
60
# 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

#priceObject



70
71
72
# File 'lib/coinsync/transaction.rb', line 70

def price
  fiat_amount / crypto_amount
end

#purchase?Boolean

Returns:

  • (Boolean)


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

def purchase?
  type == TYPE_PURCHASE
end

#sale?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/coinsync/transaction.rb', line 30

def sale?
  type == TYPE_SALE
end

#swap?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/coinsync/transaction.rb', line 34

def swap?
  type == TYPE_SWAP
end

#typeObject



14
15
16
17
18
19
20
21
22
23
24
# 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