Class: Ubea::Offer
- Inherits:
-
Object
- Object
- Ubea::Offer
- Defined in:
- lib/ubea/offer.rb
Instance Attribute Summary collapse
-
#price ⇒ Object
Returns the value of attribute price.
-
#volume ⇒ Object
Returns the value of attribute volume.
-
#weighted_price ⇒ Object
Returns the value of attribute weighted_price.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Offer
constructor
A new instance of Offer.
- #inspect ⇒ Object (also: #to_s)
- #to_h ⇒ Object
Constructor Details
#initialize(hash) ⇒ Offer
Returns a new instance of Offer.
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
#price ⇒ Object
Returns the value of attribute price.
5 6 7 |
# File 'lib/ubea/offer.rb', line 5 def price @price end |
#volume ⇒ Object
Returns the value of attribute volume.
5 6 7 |
# File 'lib/ubea/offer.rb', line 5 def volume @volume end |
#weighted_price ⇒ Object
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
#inspect ⇒ Object 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_h ⇒ Object
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 |