class Oddsmaker::Odd::Base

@abstract Base class to implement common functionality to various types of odds.

Attributes

id[R]
name[R]
value[R]

Public Instance Methods

<=>(other) click to toggle source

Compare two odds against each other.

@param other [Odd] @return [-1,0,1]

# File lib/oddsmaker/odd/base.rb, line 58
def <=>(other)
  implied_probability <=> other.implied_probability
end
==(other) click to toggle source

Check two odds for equality.

@param other [Odd] @return [Boolean]

# File lib/oddsmaker/odd/base.rb, line 50
def ==(other)
  implied_probability == other.implied_probability
end
implied_probability() click to toggle source

Calculate implied probability.

@return [ImpliedProbability]

# File lib/oddsmaker/odd/base.rb, line 34
def implied_probability
  @implied_probability ||= ImpliedProbability.new(calculate_probability, id)
end
multiplier() click to toggle source

Multiplier is commonly used for parlay and other calculations. It's just decimal odds, but we define it to match common terminology.

@return [Float]

# File lib/oddsmaker/odd/base.rb, line 42
def multiplier
  self.decimal.value
end
overround!(v) click to toggle source

Calculates a new odd, with the given overround percentage.

@param v [Integer] Overround percentage (as whole number) @return [Odd] Returns the same class as the original object

# File lib/oddsmaker/odd/base.rb, line 27
def overround!(v)
  implied_probability.overround!(v).send(type)
end
profit(amount) click to toggle source

Calculate profit for an amount wagered. Convenient if a `Wager` object is unnecessary.

@param amount [Integer, Float] Amount wagered. Can be integer or float. @return [Float, Integer, Rational]

# File lib/oddsmaker/odd/base.rb, line 75
def profit(amount)
  calculate_profit(amount)
end
to_h() click to toggle source

Represent odd as a hash. This will include all forms of the odd. @return [Hash]

# 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() click to toggle source

JSON representation of the odd. @return [String]

# File lib/oddsmaker/odd/base.rb, line 94
def to_json
  to_h.to_json
end
to_s() click to toggle source

Display odds as a string

@return [String]

# File lib/oddsmaker/odd/base.rb, line 12
def to_s
  @value.to_s
end
wager(amount) click to toggle source

Make a wager with this odd.

@param amount [Integer, Float] Amount wagered. Can be integer or float. @return [Wager]

# File lib/oddsmaker/odd/base.rb, line 66
def wager(amount)
  Wager.new(amount, self)
end
without_vig(total_probability) click to toggle source

Calculates a new odd, removing the vig.

@return [Odd] Returns the same class as the original object

# File lib/oddsmaker/odd/base.rb, line 19
def without_vig(total_probability)
  @without_vig = implied_probability.without_vig(total_probability).send(type)
end