lib/eia/ibge.rb in eia-1.1.4 vs lib/eia/ibge.rb in eia-1.2.5
- old
+ new
@@ -63,16 +63,18 @@
def consume_json(json_string, table_code)
begin
output = JSON.parse(json_string)
heading = output.delete_at(0)
- identifier = heading["D1C"]
+ identifier = heading["D1N"]
if identifier.include? "Trimestre Móvel" then
periodicity = 4
elsif identifier.include? "Ano" then
periodicity = 5
+ elsif identifier.include? "Mês" then
+ periodicity = 2
else
puts "Error! Unexpected case! Found is: #{identifier}. Report to the dev team."
return Array.new
end
@@ -80,11 +82,11 @@
output.each do |hash|
data = nil
date = nil
variable = nil
- product = nil
+ classification = Array.new
location = nil
unit = nil
val = nil
hash.each do |key, value|
@@ -93,21 +95,23 @@
date = value
when "D2N" #variable
variable = value
when "D3N" #location
location = value
- when "D4N" #product
- product = value
when "MN" #unit
unit = value
when "V" #value
val = value.to_f
else
- #This information is discarded
+ if key.include? "D" and key.include? "N" and key[1].to_i > 3 then
+ classification << "#{heading[key]}: #{value}"
+ end
+ #Else this information is discarded
end
end
- data_array << DataIBGE.new(table_code, date, variable, location, product, unit, val, periodicity)
+ data_array << DataIBGE.new(table_code, date, variable, location,
+ classification, unit, val, periodicity)
end
return data_array
rescue Exception => e