Class: ROdds::InferOddFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/r_odds/infer_odd_format.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ InferOddFormat



8
9
10
# File 'lib/r_odds/infer_odd_format.rb', line 8

def initialize(params)
  @odd = params[:odd]
end

Class Method Details

.of(params) ⇒ Object



4
5
6
# File 'lib/r_odds/infer_odd_format.rb', line 4

def self.of(params)
  new(params).call
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/r_odds/infer_odd_format.rb', line 12

def call
  case odd
  when /^(?:[1-9]\d*)+(\/|:)(?:[1-9]\d*)+$/
    :fractional
  when /^[+-][1-9]\d{2,}\.?\d*$/
    :american
  when /\d*.?\d++%/
    :implied_probability
  when /^[1-9]\d*(\.\d+)$/
    :decimal
  else
    raise ArgumentError, "Odd given in unknown format. See docs for acceptable formats"
  end
end