Class: Oddsmaker::Wager
- Inherits:
-
Object
- Object
- Oddsmaker::Wager
- Defined in:
- lib/oddsmaker/wager.rb
Overview
Wager represents an odd and a wagered amount. Odds can directly calculate their profit, so this is just a convenience class.
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#odd ⇒ Object
readonly
Returns the value of attribute odd.
Instance Method Summary collapse
-
#initialize(amount, odd) ⇒ Wager
constructor
A new instance of Wager.
-
#profit ⇒ Float, Integer
Calculate profit for a wager.
-
#return ⇒ Float, Integer
Calculate return for a wager.
-
#to_h ⇒ Hash
Hash representation of the wager.
-
#to_json ⇒ String
JSON representation of the wager.
Constructor Details
#initialize(amount, odd) ⇒ Wager
Returns a new instance of Wager.
7 8 9 10 |
# File 'lib/oddsmaker/wager.rb', line 7 def initialize(amount, odd) @amount = amount @odd = odd end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
5 6 7 |
# File 'lib/oddsmaker/wager.rb', line 5 def amount @amount end |
#odd ⇒ Object (readonly)
Returns the value of attribute odd.
5 6 7 |
# File 'lib/oddsmaker/wager.rb', line 5 def odd @odd end |
Instance Method Details
#profit ⇒ Float, Integer
Calculate profit for a wager.
15 16 17 |
# File 'lib/oddsmaker/wager.rb', line 15 def profit @profit ||= odd.profit(@amount) end |
#return ⇒ Float, Integer
Calculate return for a wager. Return is profit plus wager amount.
23 24 25 |
# File 'lib/oddsmaker/wager.rb', line 23 def return @return ||= profit + @amount end |
#to_h ⇒ Hash
Hash representation of the wager.
29 30 31 32 33 34 35 36 |
# File 'lib/oddsmaker/wager.rb', line 29 def to_h { amount: self.amount.to_f, profit: self.profit.to_f, return: self.return.to_f, odd: odd.to_h, } end |
#to_json ⇒ String
JSON representation of the wager.
40 41 42 |
# File 'lib/oddsmaker/wager.rb', line 40 def to_json to_h.to_json end |