Class: Moneybags

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

Defined Under Namespace

Modules: RemoteService Classes: MissingRateError, ServiceUnavailableError, YahooCurrencyService

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.build_key(from, to) ⇒ Object



41
42
43
44
# File 'lib/moneybags.rb', line 41

def build_key(from, to)
  [sanitize_currency_code!(from),
   sanitize_currency_code!(to)]
end

.lookup(from, to) ⇒ Object



36
37
38
39
# File 'lib/moneybags.rb', line 36

def lookup(from, to)
  key = build_key(from, to)
  YahooCurrencyService.lookup(from, to)
end

.sanitize_currency_code!(code) ⇒ Object

Raises:

  • (ArgumentError)


46
47
48
49
50
51
# File 'lib/moneybags.rb', line 46

def sanitize_currency_code!(code)
  code.gsub!(/[^A-Z]+/, '') rescue nil
  code.strip! rescue nil
  raise ArgumentError if code.nil? || code.empty?
  code
end