Class: Ubea::Offer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Offer

Returns a new instance of Offer.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
# File 'lib/ubea/offer.rb', line 7

def initialize(hash)
  self.price = hash.delete(:price)
  self.weighted_price = hash.delete(:weighted_price)
  self.volume = Money.new(hash.delete(:volume), "BTC")

  raise ArgumentError unless hash.empty?
  raise ArgumentError, "#{price.class} is not Money" unless price.is_a? Money
end

Instance Attribute Details

#priceObject

Returns the value of attribute price.



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

def price
  @price
end

#volumeObject

Returns the value of attribute volume.



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

def volume
  @volume
end

#weighted_priceObject

Returns the value of attribute weighted_price.



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

def weighted_price
  @weighted_price
end

Instance Method Details

#inspectObject Also known as: to_s



24
25
26
# File 'lib/ubea/offer.rb', line 24

def inspect
  "#<Ubea::Offer price=#{price} volume=#{volume}>"
end

#to_hObject



16
17
18
19
20
21
22
# File 'lib/ubea/offer.rb', line 16

def to_h
  {
    weighted_price: weighted_price.to_f.to_s,
    limit_price: price.to_f.to_s,
    volume: volume.to_f.to_s,
  }
end