class Helper
Public Class Methods
new()
click to toggle source
# File lib/eba/helper.rb, line 5 def initialize() end
Public Instance Methods
build_bcb_data(xml_result)
click to toggle source
# File lib/eba/helper.rb, line 8 def build_bcb_data(xml_result) d = Data_bcb.new(xml_result) if d.name[" - com ajuste sazonal"] != nil then d.seasonally_adjusted = true if d.seasonally_adjusted then d.name.slice!(" - com ajuste sazonal") end end d.name = encode(d.name) d.periodicity = encode(d.periodicity) d.unit = encode(d.unit) d.value = encode(d.value) return d end
extract_an_item(serie, code_x_data_hash, collection)
click to toggle source
# File lib/eba/helper.rb, line 42 def extract_an_item(serie, code_x_data_hash, collection) # recover identifying data from the getLastValue method, # as the get_valores_series_xml desn't have identifying data # as series name, periodicity, etc. if serie.to_s.inspect["SERIE ID"] != nil then code = serie.to_s.match(/SERIE ID=\"([0-9]+)\"/)[1].to_i base_data = code_x_data_hash[code] if base_data != nil then serie.css("ITEM").each do |item| dia = "01" mes = "1" ano = "1" data = item.css("DATA").text.split("/") if base_data.periodicity == 'D' then dia = data[0] mes = data[1] ano = data[2] else mes = data[0] ano = data[1] end collection << Data_bcb.new([base_data.name, code, base_data.periodicity, base_data.unit, dia, mes, ano, item.css("VALOR").text, base_data.seasonally_adjusted]) end else puts "ERROR BCB: Failure do locate #{code} in the data collection #{code_x_data_hash.keys}" end end end
purge_invalid_series(array_of_codes, hash_last_values)
click to toggle source
Removes all invalid series from an array.
An invalid series has last value.
# File lib/eba/helper.rb, line 30 def purge_invalid_series(array_of_codes, hash_last_values) result = [] array_of_codes.each do |code| if hash_last_values[code] != nil then result << code end end return result end