Class Units::Converter::ExchangeRate
In: lib/facets/more/units.rb
Parent: Object

Encapsulates a service for retrieving exchange rates. This is used by Converter.register_currency. An instance of this class behaves like a Numeric when used in calculations. This class is used to look up exchange rates lazily.

This class is not supposed to be instantiated by itself. Instead a subclass should be created that defines the method get_rate. The only subclass provided is currently XMethods.

To be found automatically from YAML files, exchange services should be located under Units::Converter::ExchangeRate.

Methods

get_rate  

Classes and Modules

Class Units::Converter::ExchangeRate::CachedXMethods
Class Units::Converter::ExchangeRate::XMethods

Public Instance methods

This method should be overridden in subclasses to return the exchange rate represented by this object. The unit in question is available as a String in the instance variable @curr. The rate should be calculated against an arbitrary but fixed base currency. The rate should be such that the following would be true

  1 * curr = rate * base_curr

This function should return nil if the currency is not supported by this retrieval service. It should not raise an exception.

[Validate]