Class: Oddx::Odds
- Inherits:
-
Object
show all
- Defined in:
- lib/oddx/odds.rb
Constant Summary
collapse
- BIGDECIMAL_SIG_DIGITS =
3
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Odds
Returns a new instance of Odds.
9
10
11
|
# File 'lib/oddx/odds.rb', line 9
def initialize
raise NotImplementedError
end
|
Instance Method Details
#decimal ⇒ Object
13
14
15
|
# File 'lib/oddx/odds.rb', line 13
def decimal
"%g" % (@bigdecimal_odds.round(2))
end
|
#fractional ⇒ Object
17
18
19
|
# File 'lib/oddx/odds.rb', line 17
def fractional
(@bigdecimal_odds - 1).to_r.rationalize.to_s
end
|
#moneyline ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/oddx/odds.rb', line 21
def moneyline
if @bigdecimal_odds >= 2
"+%g" % ((@bigdecimal_odds - 1) * 100).round(1)
else
"%g" % (-100 / (@bigdecimal_odds - 1)).round(1)
end
end
|
#probability ⇒ Object
29
30
31
|
# File 'lib/oddx/odds.rb', line 29
def probability
"%g%%" % ((1 / @bigdecimal_odds) * 100).round(1)
end
|
#to_s ⇒ Object
33
34
35
|
# File 'lib/oddx/odds.rb', line 33
def to_s
"Fractional: #{fractional}, Moneyline: #{moneyline}, Decimal: #{decimal}, Implied Probability: #{probability}"
end
|