class Exchange::ExternalAPI::ValutaKg

Constants

API_URL
CURRENCIES

Public Instance Methods

update(opts={}) click to toggle source
# File lib/exchange/external_api/valuta_kg.rb, line 10
def update opts={}
  time = helper.assure_time(opts[:at], default: :now)

  Call.new(API_URL, at: time, format: :xml) do |result|
    @base = :kgs

    @rates = result.search('currency').map do |c|
      [
        c.at("title_alias").text.downcase.to_sym,
        (1 / BigDecimal.new(c.at('buy_rate').text.sub(',', '.')))
      ]
    end.to_h.merge({ kgs: 1 })

    @timestamp = Date.today.to_time.to_i
  end
end