Class: Heisencoin::Trade

Inherits:
Object
  • Object
show all
Defined in:
lib/heisencoin/trade.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_offerObject

Returns the value of attribute from_offer.



3
4
5
# File 'lib/heisencoin/trade.rb', line 3

def from_offer
  @from_offer
end

#quantityObject

Returns the value of attribute quantity.



3
4
5
# File 'lib/heisencoin/trade.rb', line 3

def quantity
  @quantity
end

#to_offerObject

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

#costObject



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

#profitObject



31
32
33
34
# File 'lib/heisencoin/trade.rb', line 31

def profit
  earned = to_offer.cost(@quantity)
  earned - cost
end

#to_simpleObject



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