Class: Oddsmaker::Odd::Base Abstract
- Inherits:
-
Object
- Object
- Oddsmaker::Odd::Base
- Includes:
- Comparable
- Defined in:
- lib/oddsmaker/odd/base.rb
Overview
Base class to implement common functionality to various types of odds.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
(also: #name)
readonly
Returns the value of attribute id.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Compare two odds against each other.
-
#==(other) ⇒ Boolean
Check two odds for equality.
-
#implied_probability ⇒ ImpliedProbability
Calculate implied probability.
-
#multiplier ⇒ Float
Multiplier is commonly used for parlay and other calculations.
-
#overround!(v) ⇒ Odd
Calculates a new odd, with the given overround percentage.
-
#profit(amount) ⇒ Float, ...
Calculate profit for an amount wagered.
-
#to_h ⇒ Hash
Represent odd as a hash.
-
#to_json ⇒ String
JSON representation of the odd.
-
#to_s ⇒ String
Display odds as a string.
-
#wager(amount) ⇒ Wager
Make a wager with this odd.
-
#without_vig(total_probability) ⇒ Odd
Calculates a new odd, removing the vig.
Instance Attribute Details
#id ⇒ Object (readonly) Also known as: name
Returns the value of attribute id.
6 7 8 |
# File 'lib/oddsmaker/odd/base.rb', line 6 def id @id end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/oddsmaker/odd/base.rb', line 6 def value @value end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Compare two odds against each other.
58 59 60 |
# File 'lib/oddsmaker/odd/base.rb', line 58 def <=>(other) implied_probability <=> other.implied_probability end |
#==(other) ⇒ Boolean
Check two odds for equality.
50 51 52 |
# File 'lib/oddsmaker/odd/base.rb', line 50 def ==(other) implied_probability == other.implied_probability end |
#implied_probability ⇒ ImpliedProbability
Calculate implied probability.
34 35 36 |
# File 'lib/oddsmaker/odd/base.rb', line 34 def implied_probability @implied_probability ||= ImpliedProbability.new(calculate_probability, id) end |
#multiplier ⇒ Float
Multiplier is commonly used for parlay and other calculations. It’s just decimal odds, but we define it to match common terminology.
42 43 44 |
# File 'lib/oddsmaker/odd/base.rb', line 42 def multiplier self.decimal.value end |
#overround!(v) ⇒ Odd
Calculates a new odd, with the given overround percentage.
27 28 29 |
# File 'lib/oddsmaker/odd/base.rb', line 27 def overround!(v) implied_probability.overround!(v).send(type) end |
#profit(amount) ⇒ Float, ...
Calculate profit for an amount wagered. Convenient if a ‘Wager` object is unnecessary.
75 76 77 |
# File 'lib/oddsmaker/odd/base.rb', line 75 def profit(amount) calculate_profit(amount) end |
#to_h ⇒ Hash
Represent odd as a hash. This will include all forms of the odd.
82 83 84 85 86 87 88 89 90 |
# File 'lib/oddsmaker/odd/base.rb', line 82 def to_h { name: self.name, american: self.american.value, decimal: self.decimal.value, fractional: self.fractional.value, implied: self.implied_probability.value, } end |
#to_json ⇒ String
JSON representation of the odd.
94 95 96 |
# File 'lib/oddsmaker/odd/base.rb', line 94 def to_json to_h.to_json end |
#to_s ⇒ String
Display odds as a string
12 13 14 |
# File 'lib/oddsmaker/odd/base.rb', line 12 def to_s @value.to_s end |
#wager(amount) ⇒ Wager
Make a wager with this odd.
66 67 68 |
# File 'lib/oddsmaker/odd/base.rb', line 66 def wager(amount) Wager.new(amount, self) end |
#without_vig(total_probability) ⇒ Odd
Calculates a new odd, removing the vig.
19 20 21 |
# File 'lib/oddsmaker/odd/base.rb', line 19 def without_vig(total_probability) @without_vig = implied_probability.without_vig(total_probability).send(type) end |