Class: Heisencoin::Trade
- Inherits:
-
Object
- Object
- Heisencoin::Trade
- Defined in:
- lib/heisencoin/trade.rb
Instance Attribute Summary collapse
-
#from_offer ⇒ Object
Returns the value of attribute from_offer.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#to_offer ⇒ Object
Returns the value of attribute to_offer.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cost ⇒ Object
- #from_simple(simple) ⇒ Object
-
#initialize(simple = nil) ⇒ Trade
constructor
A new instance of Trade.
- #profit ⇒ Object
- #to_simple ⇒ Object
Constructor Details
#initialize(simple = nil) ⇒ Trade
Returns a new instance of Trade.
5 6 7 |
# File 'lib/heisencoin/trade.rb', line 5 def initialize(simple = nil) from_simple(simple) if simple end |
Instance Attribute Details
#from_offer ⇒ Object
Returns the value of attribute from_offer.
3 4 5 |
# File 'lib/heisencoin/trade.rb', line 3 def from_offer @from_offer end |
#quantity ⇒ Object
Returns the value of attribute quantity.
3 4 5 |
# File 'lib/heisencoin/trade.rb', line 3 def quantity @quantity end |
#to_offer ⇒ Object
Returns the value of attribute to_offer.
3 4 5 |
# File 'lib/heisencoin/trade.rb', line 3 def to_offer @to_offer end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 24 25 |
# File 'lib/heisencoin/trade.rb', line 21 def ==(other) @from_offer == other.from_offer @to_offer == other.to_offer @quantity == other.quantity end |
#cost ⇒ Object
27 28 29 |
# File 'lib/heisencoin/trade.rb', line 27 def cost from_offer.cost(@quantity) end |
#from_simple(simple) ⇒ Object
9 10 11 12 13 |
# File 'lib/heisencoin/trade.rb', line 9 def from_simple(simple) @from_offer = Offer.new(simple['from_offer']) @to_offer = Offer.new(simple['to_offer']) @quantity = simple['quantity'] end |
#profit ⇒ Object
31 32 33 34 |
# File 'lib/heisencoin/trade.rb', line 31 def profit earned = to_offer.cost(@quantity) earned - cost end |
#to_simple ⇒ Object
15 16 17 18 19 |
# File 'lib/heisencoin/trade.rb', line 15 def to_simple {'from_offer' => @from_offer.to_simple, 'to_offer' => @to_offer.to_simple, 'quantity' => @quantity} end |