Class: Oddsmaker::Wager

Inherits:
Object
  • Object
show all
Defined in:
lib/oddsmaker/wager.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, odd) ⇒ Wager

Returns a new instance of Wager.



7
8
9
10
# File 'lib/oddsmaker/wager.rb', line 7

def initialize(amount, odd)
  @amount = amount
  @odd = odd
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/oddsmaker/wager.rb', line 5

def amount
  @amount
end

#oddObject (readonly)

Returns the value of attribute odd.



5
6
7
# File 'lib/oddsmaker/wager.rb', line 5

def odd
  @odd
end

Instance Method Details

#profitFloat, Integer

Calculate profit for a wager.

Returns:

  • (Float, Integer)


15
16
17
# File 'lib/oddsmaker/wager.rb', line 15

def profit
  @profit ||= odd.profit(@amount)
end

#returnFloat, Integer

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

Returns:

  • (Float, Integer)


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

def return
  @return ||= profit + @amount
end

#to_hHash

Hash representation of the wager.

Returns:

  • (Hash)


29
30
31
32
33
34
35
36
# 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_jsonString

JSON representation of the wager.

Returns:

  • (String)


40
41
42
# File 'lib/oddsmaker/wager.rb', line 40

def to_json
  to_h.to_json
end