Class: Oddx::Odds

Inherits:
Object
  • Object
show all
Defined in:
lib/oddx/odds.rb

Constant Summary collapse

BIGDECIMAL_SIG_DIGITS =
3

Instance Method Summary collapse

Constructor Details

#initializeOdds

Returns a new instance of Odds.

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/oddx/odds.rb', line 9

def initialize
  raise NotImplementedError
end

Instance Method Details

#decimalObject



13
14
15
# File 'lib/oddx/odds.rb', line 13

def decimal
  "%g" % (@bigdecimal_odds.round(2))
end

#fractionalObject



17
18
19
# File 'lib/oddx/odds.rb', line 17

def fractional
  (@bigdecimal_odds - 1).to_r.rationalize.to_s
end

#moneylineObject



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

#probabilityObject



29
30
31
# File 'lib/oddx/odds.rb', line 29

def probability
  "%g%%" % ((1 / @bigdecimal_odds) * 100).round(1)
end

#to_sObject



33
34
35
# File 'lib/oddx/odds.rb', line 33

def to_s
  "Fractional: #{fractional}, Moneyline: #{moneyline}, Decimal: #{decimal}, Implied Probability: #{probability}"
end