Class: Currency::Exchange::Rate::Source::Test

Inherits:
Provider show all
Defined in:
lib/currency/exchange/rate/source/test.rb

Overview

This class is a test Rate Source. It can provide only fixed rates between USD, CAD and EUR. Used only for test purposes. DO NOT USE THESE RATES FOR A REAL APPLICATION.

Constant Summary collapse

@@instance =
nil

Instance Attribute Summary

Attributes inherited from Provider

#date, #uri, #uri_path

Attributes inherited from Base

#pivot_currency, #time_quantitizer, #verbose

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Provider

#available?, #clear_rates, #date_DD, #date_MM, #date_YYYY, #get_page_content, #get_rate, #get_uri, #load_rates

Methods inherited from Base

#__subclass_responsibility, #clear_rate, #clear_rates, #convert, #currencies, #get_rate, #get_rate_base, #get_rates, #new_rate, #normalize_time, #rate, #to_s

Constructor Details

#initialize(*opts) ⇒ Test

Returns a new instance of Test.



19
20
21
22
# File 'lib/currency/exchange/rate/source/test.rb', line 19

def initialize(*opts)
 self.uri = 'none://localhost/Test'
 super(*opts)
end

Class Method Details

.instance(*opts) ⇒ Object

Returns a singleton instance.



14
15
16
# File 'lib/currency/exchange/rate/source/test.rb', line 14

def self.instance(*opts)
  @@instance ||= self.new(*opts)
end

.USD_CADObject

Test rate from :USD to :CAD.



30
# File 'lib/currency/exchange/rate/source/test.rb', line 30

def self.USD_CAD; 1.1708; end

.USD_EURObject

Test rate from :USD to :EUR.



34
# File 'lib/currency/exchange/rate/source/test.rb', line 34

def self.USD_EUR; 0.7737; end

.USD_GBPObject

Test rate from :USD to :GBP.



38
# File 'lib/currency/exchange/rate/source/test.rb', line 38

def self.USD_GBP; 0.5098; end

Instance Method Details

#nameObject



25
26
27
# File 'lib/currency/exchange/rate/source/test.rb', line 25

def name
  'Test'
end

#ratesObject

Returns test Rate for USD to [ CAD, EUR, GBP ].



42
43
44
45
46
# File 'lib/currency/exchange/rate/source/test.rb', line 42

def rates
  [ new_rate(:USD, :CAD, self.class.USD_CAD),
    new_rate(:USD, :EUR, self.class.USD_EUR),
    new_rate(:USD, :GBP, self.class.USD_GBP) ]
end