Class: Oddsmaker::Odd::American
- 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
Instance Method Summary collapse
-
#american ⇒ self
Returns self.
-
#decimal ⇒ Decimal
Convert to decimal odds, returning a new object.
-
#fractional ⇒ Fractional
Convert to fractional odds, returning a new object.
-
#initialize(value, id = nil) ⇒ American
constructor
A new instance of American.
-
#to_s ⇒ String
Properly display both positive and negative odds.
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
#american ⇒ self
Returns self. This creates a consistent API for all odds.
23 24 25 |
# File 'lib/oddsmaker/odd/american.rb', line 23 def american self end |
#decimal ⇒ Decimal
Convert to decimal odds, returning a new object.
30 31 32 |
# File 'lib/oddsmaker/odd/american.rb', line 30 def decimal @decimal ||= implied_probability.decimal end |
#fractional ⇒ Fractional
Convert to fractional odds, returning a new object.
37 38 39 |
# File 'lib/oddsmaker/odd/american.rb', line 37 def fractional @fractional ||= Fractional.new(calculate_fractional, id) end |
#to_s ⇒ String
Properly display both positive and negative odds.
16 17 18 |
# File 'lib/oddsmaker/odd/american.rb', line 16 def to_s @value.positive? ? "+#{@value}" : @value.to_s end |