class CurrencyToWords::Currency

Base class that will load language specific class with specific language algorithm.

Attributes

number_parts[R]
options[R]
texterizer[R]

Public Class Methods

new(lang_class, splitted_number, options = {}) click to toggle source

constructor of Currency class

# File lib/currency_to_words.rb, line 66
def initialize lang_class, splitted_number, options = {}
  @lang_class   = lang_class
  @number_parts = splitted_number
  @options      = options
end

Public Instance Methods

process() click to toggle source

Process and try to find language specific for current locale!

# File lib/currency_to_words.rb, line 73
def process
  if @lang_class.respond_to?('process')
    processed_number = @lang_class.process @number_parts
    if processed_number.is_a?(String)
      return processed_number
    else
      raise TypeError, "a lang_class must return a String" if @options[:raise]
    end
  else
    raise NoMethodError, "a lang_class must provide a 'lang_class' method" if @options[:raise]
  end

  # fallback on CsCurrency
  unless @lang_class.instance_of?(CsCurrency)
    @lang_class = CsCurrency.new
    self.process
  else
    raise RuntimeError, "you should use the option ':raise => true' to see what goes wrong"
  end
end