lib/FixedOdds.rb in rodders-0.1.2 vs lib/FixedOdds.rb in rodders-0.2.0
- old
+ new
@@ -24,25 +24,25 @@
# tells if the odds are in fractional form
# @param [String] odds the odds representation
# @return [Boolean] to indicate if it matches
def FixedOdds.fractional_odds?(odds)
- odds =~ /\d+\/\d+|\d+-to-\d+|evens|even money/
+ odds =~ /^(\d+(\/|-to-)\d+( (against|on))?|evens|even money)$/
end
# tells if the odds are in moneyline form
# @param (see FixedOdds.fractional_odds?)
# @return (see FixedOdds.fractional_odds?)
def FixedOdds.moneyline_odds?(odds)
- odds =~ /[+-]\d+/
+ odds =~ /^[+-]\d+$/
end
# tells if the odds are in decimal form
# @param (see FixedOdds.fractional_odds?)
# @return (see FixedOdds.fractional_odds?)
def FixedOdds.decimal_odds?(odds)
- odds =~ /^(\d+|\d+\.\d+|\.\d+)/
+ odds =~ /^(\d+|\d+\.\d+|\.\d+)$/
end
# creates a new FixedOdds from fractional form. These can be in the form
# * 4-to-1
# * 4-to-1 against
@@ -102,9 +102,17 @@
# (which is the profit plus the initial stake)
# @param (see #profit_on_winning_stake)
# @return [Money] the total winnings
def total_return_on_winning_stake(stake)
profit_on_winning_stake(stake) + stake.to_money
+ end
+
+ # calculates the magnitude of the stake needed to
+ # win the specified amount in profit
+ # @param [String] win the desired profit
+ # @return [Money] the stake required to realise that profit on a winning bet
+ def stake_needed_to_win win
+ win.to_money / @fractional_odds
end
# string representation in fractional form like '4/1'
# @return [String] fractional form representation
def to_s