Class: Oddsmaker::Odd::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/oddsmaker/odd/base.rb

Overview

This class is abstract.

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

Direct Known Subclasses

American, Decimal, Fractional, ImpliedProbability

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (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

#valueObject (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.

Parameters:

Returns:

  • (-1, 0, 1)


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.

Parameters:

Returns:

  • (Boolean)


50
51
52
# File 'lib/oddsmaker/odd/base.rb', line 50

def ==(other)
  implied_probability == other.implied_probability
end

#implied_probabilityImpliedProbability

Calculate implied probability.

Returns:



34
35
36
# File 'lib/oddsmaker/odd/base.rb', line 34

def implied_probability
  @implied_probability ||= ImpliedProbability.new(calculate_probability, id)
end

#multiplierFloat

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

Returns:

  • (Float)


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.

Parameters:

  • v (Integer)

    Overround percentage (as whole number)

Returns:

  • (Odd)

    Returns the same class as the original object



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.

Parameters:

  • amount (Integer, Float)

    Amount wagered. Can be integer or float.

Returns:

  • (Float, Integer, Rational)


75
76
77
# File 'lib/oddsmaker/odd/base.rb', line 75

def profit(amount)
  calculate_profit(amount)
end

#to_hHash

Represent odd as a hash. This will include all forms of the odd.

Returns:

  • (Hash)


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_jsonString

JSON representation of the odd.

Returns:

  • (String)


94
95
96
# File 'lib/oddsmaker/odd/base.rb', line 94

def to_json
  to_h.to_json
end

#to_sString

Display odds as a string

Returns:

  • (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.

Parameters:

  • amount (Integer, Float)

    Amount wagered. Can be integer or float.

Returns:



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.

Returns:

  • (Odd)

    Returns the same class as the original object



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