Class: Oddsmaker::Odd::American

Inherits:
Base
  • Object
show all
Defined in:
lib/oddsmaker/odd/american.rb

Overview

American Odds class, handling both positive and negative odds. A negative value expresses the dollar amount that would need to be wagered in order to win $100. A positive number expresses the dollar amount that would be won from a $100 wager, excluding the original wager.

Instance Attribute Summary

Attributes inherited from Base

#id, #value

Instance Method Summary collapse

Methods inherited from Base

#<=>, #==, #implied_probability, #multiplier, #overround!, #profit, #to_h, #to_json, #wager, #without_vig

Constructor Details

#initialize(value, id = nil) ⇒ American

Returns a new instance of American.



8
9
10
11
# File 'lib/oddsmaker/odd/american.rb', line 8

def initialize(value, id = nil)
  @id    = id || value
  @value = value.to_i
end

Instance Method Details

#americanself

Returns self. This creates a consistent API for all odds.

Returns:

  • (self)


23
24
25
# File 'lib/oddsmaker/odd/american.rb', line 23

def american
  self
end

#decimalDecimal

Convert to decimal odds, returning a new object.

Returns:



30
31
32
# File 'lib/oddsmaker/odd/american.rb', line 30

def decimal
  @decimal ||= implied_probability.decimal
end

#fractionalFractional

Convert to fractional odds, returning a new object.

Returns:



37
38
39
# File 'lib/oddsmaker/odd/american.rb', line 37

def fractional
  @fractional ||= Fractional.new(calculate_fractional, id)
end

#to_sString

Properly display both positive and negative odds.

Returns:

  • (String)


16
17
18
# File 'lib/oddsmaker/odd/american.rb', line 16

def to_s
  @value.positive? ? "+#{@value}" : @value.to_s
end