Class: ECB::Exchange::XMLFeed

Inherits:
Object
  • Object
show all
Defined in:
lib/ecb/exchange/xml_feed.rb

Constant Summary collapse

NINETY_DAY_ENDPOINT =
"http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.endpointObject

Returns the value of attribute endpoint


14
15
16
# File 'lib/ecb/exchange/xml_feed.rb', line 14

def endpoint
  @endpoint
end

Class Method Details

.rates(date) ⇒ Object


21
22
23
24
25
26
27
28
29
30
# File 'lib/ecb/exchange/xml_feed.rb', line 21

def self.rates(date)
  if date > Date.today
    raise ArgumentError.new("invalid date, must be today or in the past")
  end

  # find rates in cache, or fetch (and cache)
  date  = date.to_s
  rates = Cache.read(date) || fetch_and_cache[date]
  rates ? rates : raise(DateNotFoundError.new(date))
end