Class: Money::BankSources::CbarAz
- Inherits:
-
Object
- Object
- Money::BankSources::CbarAz
- Defined in:
- lib/money/bank_sources/cbar_az.rb
Constant Summary collapse
- CODE_MAP =
{ # RUR is an old roubles code according to ISO 4217 "RUR" => "RUB" }
Instance Attribute Summary collapse
-
#rates ⇒ Object
readonly
Returns the value of attribute rates.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CbarAz
constructor
A new instance of CbarAz.
- #parse ⇒ Object
- #store! ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CbarAz
Returns a new instance of CbarAz.
14 15 16 17 18 19 20 |
# File 'lib/money/bank_sources/cbar_az.rb', line 14 def initialize( = {}) @date = [:date] || Date.today @bank = [:bank] || Money.default_bank @only = [:only] ? Array([:only]) : nil @data = [:data] @rates = {} end |
Instance Attribute Details
#rates ⇒ Object (readonly)
Returns the value of attribute rates.
12 13 14 |
# File 'lib/money/bank_sources/cbar_az.rb', line 12 def rates @rates end |
Instance Method Details
#parse ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/money/bank_sources/cbar_az.rb', line 22 def parse xml.elements.each("ValCurs/ValType/Valute") do |currency| code = currency.attributes["Code"] code = CODE_MAP.fetch(code, code) next if skip_code?(code) rate = currency.elements["Value"].text.to_f rates[code] = rate end self end |
#store! ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/money/bank_sources/cbar_az.rb', line 35 def store! rates.each do |code, rate| if Money::Currency.find(code) @bank.add_rate(code, :azn, rate) @bank.add_rate(:azn, code, 1.0/rate) end end @bank.save! if @bank.respond_to?(:save!) end |
#url ⇒ Object
45 46 47 |
# File 'lib/money/bank_sources/cbar_az.rb', line 45 def url @url ||= "http://cbar.az/currencies/#{formatted_date}.xml" end |