Class: Heisencoin::Offer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(simple = nil) ⇒ Offer

Returns a new instance of Offer.



5
6
7
# File 'lib/heisencoin/offer.rb', line 5

def initialize(simple = nil)
  from_simple(simple) if simple
end

Instance Attribute Details

#exchangeObject

Returns the value of attribute exchange.



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

def exchange
  @exchange
end

#priceObject

Returns the value of attribute price.



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

def price
  @price
end

#quantityObject

Returns the value of attribute quantity.



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

def quantity
  @quantity
end

Class Method Details

.from_array(exchange, raw_offer) ⇒ Object



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

def self.from_array(exchange, raw_offer)
  Offer.new({'exchange' => exchange.to_simple,
             'price' => raw_offer[0],
             'quantity' => raw_offer[1]})
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
25
# File 'lib/heisencoin/offer.rb', line 21

def ==(other)
  exchange.name == other.exchange.name
  price == other.price
  quantity = other.quantity
end

#cost(quantity) ⇒ Object



27
28
29
# File 'lib/heisencoin/offer.rb', line 27

def cost(quantity)
  quantity * price
end

#from_simple(simple) ⇒ Object



9
10
11
12
13
# File 'lib/heisencoin/offer.rb', line 9

def from_simple(simple)
  @exchange = Exchange.new(simple['exchange'])
  @price = simple['price']
  @quantity = simple['quantity']
end

#to_simpleObject



15
16
17
18
19
# File 'lib/heisencoin/offer.rb', line 15

def to_simple
  {'exchange' => exchange.to_simple,
   'price' => price,
   'quantity' => quantity}
end