Class: CoinSync::Transaction
- Inherits:
-
Object
- Object
- CoinSync::Transaction
- Includes:
- Amounts
- Defined in:
- lib/coinsync/transaction.rb
Defined Under Namespace
Modules: Amounts Classes: ConvertedAmounts
Constant Summary collapse
- TYPE_PURCHASE =
:purchase
- TYPE_SALE =
:sale
- TYPE_SWAP =
:swap
Instance Attribute Summary collapse
-
#converted ⇒ Object
Returns the value of attribute converted.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#number ⇒ Object
Returns the value of attribute number.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Attributes included from Amounts
#bought_amount, #bought_currency, #sold_amount, #sold_currency
Instance Method Summary collapse
-
#initialize(number: nil, exchange:, bought_currency:, sold_currency:, time:, bought_amount:, sold_amount:) ⇒ Transaction
constructor
A new instance of Transaction.
Methods included from Amounts
#crypto_amount, #crypto_currency, #fiat_amount, #fiat_currency, #price, #purchase?, #sale?, #swap?, #type
Constructor Details
#initialize(number: nil, exchange:, bought_currency:, sold_currency:, time:, bought_amount:, sold_amount:) ⇒ Transaction
Returns a new instance of Transaction.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/coinsync/transaction.rb', line 86 def initialize(number: nil, exchange:, bought_currency:, sold_currency:, time:, bought_amount:, sold_amount:) @number = number @exchange = exchange if time.is_a?(Time) @time = time.getlocal else raise "Transaction: '#{time}' is not a valid Time object" end if bought_amount.is_a?(BigDecimal) @bought_amount = bought_amount else raise "Transaction: '#{bought_amount}' should be a BigDecimal" end if bought_currency.is_a?(Currency) @bought_currency = bought_currency else raise "Transaction: '#{bought_currency}' is not a valid currency" end (bought_amount >= 0) or raise "Transaction: bought_amount should not be negative (#{bought_amount})" if sold_amount.is_a?(BigDecimal) @sold_amount = sold_amount else raise "Transaction: '#{sold_amount}' should be a BigDecimal" end if sold_currency.is_a?(Currency) || sold_amount == 0 @sold_currency = sold_currency else raise "Transaction: '#{sold_currency}' is not a valid currency" end (sold_amount >= 0) or raise "Transaction: sold_amount should not be negative (#{sold_amount})" end |
Instance Attribute Details
#converted ⇒ Object
Returns the value of attribute converted.
82 83 84 |
# File 'lib/coinsync/transaction.rb', line 82 def converted @converted end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
81 82 83 |
# File 'lib/coinsync/transaction.rb', line 81 def exchange @exchange end |
#number ⇒ Object
Returns the value of attribute number.
82 83 84 |
# File 'lib/coinsync/transaction.rb', line 82 def number @number end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
81 82 83 |
# File 'lib/coinsync/transaction.rb', line 81 def time @time end |