Class: Helper
Direct Known Subclasses
Instance Method Summary collapse
- #build_bcb_data(xml_result) ⇒ Object
- #extract_an_item(serie, code_x_data_hash, collection) ⇒ Object
-
#initialize ⇒ Helper
constructor
A new instance of Helper.
-
#purge_invalid_series(array_of_codes, hash_last_values) ⇒ Object
Removes all invalid series from an array.
Methods inherited from Encoder
Constructor Details
#initialize ⇒ Helper
Returns a new instance of Helper.
5 6 |
# File 'lib/eba/helper.rb', line 5 def initialize() end |
Instance Method Details
#build_bcb_data(xml_result) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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) ⇒ Object
Removes all invalid series from an array.
An invalid series has last value.
30 31 32 33 34 35 36 37 38 39 40 |
# 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 |