Class: Bnb::Rates

Inherits:
Object
  • Object
show all
Includes:
HTTParty, HTTParty::Icebox
Defined in:
lib/bnb/rates.rb

Instance Method Summary collapse

Constructor Details

#initializeRates

Returns a new instance of Rates.



9
10
11
# File 'lib/bnb/rates.rb', line 9

def initialize
  @rates = {}
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
# File 'lib/bnb/rates.rb', line 25

def [] key
  @rates[key]
end

#fetchObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bnb/rates.rb', line 13

def fetch
  response = HTTParty.get('http://www.bnb.bg/Statistics/StExternalSector/StExchangeRates/StERForeignCurrencies/index.htm?download=xml&search=&lang=BG')
  rows = response.parsed_response['ROWSET']['ROW']

  rows.each do |item|
    rate = Bnb::Rate.new.from_bnb(item)
    @rates[rate.code] = rate
  end

  self
end