class ROdds::OddConverter::ClassFactory

Attributes

from[R]
to[R]

Public Class Methods

call(params) click to toggle source
# File lib/r_odds/odd_converters/class_factory.rb, line 4
def self.call(params)
  new(params).call
end
new(params) click to toggle source
# File lib/r_odds/odd_converters/class_factory.rb, line 8
def initialize(params)
  @from = params[:from]
  @to   = params[:to]
end

Public Instance Methods

call() click to toggle source
# File lib/r_odds/odd_converters/class_factory.rb, line 13
def call
  begin
    Object.const_get("ROdds::OddConverter::#{capitalize(from)}To#{capitalize(to)}")
  rescue NameError
    raise ArgumentError,
      "No known conversion class to get from format :#{from}, to format :#{to}"
  end
end

Private Instance Methods

capitalize(symbol) click to toggle source
# File lib/r_odds/odd_converters/class_factory.rb, line 25
def capitalize(symbol)
  symbol.to_s.split('_').map(&:capitalize).join
end