Class: Trader::Price
- Inherits:
-
Object
- Object
- Trader::Price
- Defined in:
- lib/trade-o-matic/structs/price.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
Instance Method Summary collapse
- #convert_to(_other_currency) ⇒ Object
-
#initialize(_currency, _amount) ⇒ Price
constructor
A new instance of Price.
- #pack(_amount) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(_currency, _amount) ⇒ Price
Returns a new instance of Price.
5 6 7 8 |
# File 'lib/trade-o-matic/structs/price.rb', line 5 def initialize(_currency, _amount) @currency = Currency.for_code _currency @amount = Standard.amount _amount end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
3 4 5 |
# File 'lib/trade-o-matic/structs/price.rb', line 3 def amount @amount end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
3 4 5 |
# File 'lib/trade-o-matic/structs/price.rb', line 3 def currency @currency end |
Instance Method Details
#convert_to(_other_currency) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/trade-o-matic/structs/price.rb', line 14 def convert_to(_other_currency) _other_currency = Currency.for_code _other_currency return self if _other_currency == currency new_amount = @currency.convert amount, _other_currency Price.new _other_currency, new_amount end |
#pack(_amount) ⇒ Object
10 11 12 |
# File 'lib/trade-o-matic/structs/price.rb', line 10 def pack(_amount) currency.pack _amount end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/trade-o-matic/structs/price.rb', line 23 def to_s "#{amount} #{currency.code}" end |