class Oddsmaker::Wager

Wager represents an odd and a wagered amount. Odds can directly calculate their profit, so this is just a convenience class.

Attributes

amount[R]
odd[R]

Public Class Methods

new(amount, odd) click to toggle source
# File lib/oddsmaker/wager.rb, line 7
def initialize(amount, odd)
  @amount = amount
  @odd = odd
end

Public Instance Methods

profit() click to toggle source

Calculate profit for a wager.

@return [Float, Integer]

# File lib/oddsmaker/wager.rb, line 15
def profit
  @profit ||= odd.profit(@amount)
end
return() click to toggle source

Calculate return for a wager. Return is profit plus wager amount.

@return [Float, Integer]

# File lib/oddsmaker/wager.rb, line 23
def return
  @return ||= profit + @amount
end
to_h() click to toggle source

Hash representation of the wager. @return [Hash]

# File lib/oddsmaker/wager.rb, line 29
def to_h
  {
    amount:  self.amount.to_f,
    profit:  self.profit.to_f,
    return:  self.return.to_f,
    odd:     odd.to_h,
  }
end
to_json() click to toggle source

JSON representation of the wager. @return [String]

# File lib/oddsmaker/wager.rb, line 40
def to_json
  to_h.to_json
end