lib/eia/data.rb in eia-1.7.7 vs lib/eia/data.rb in eia-1.8.7
- old
+ new
@@ -1,6 +1,9 @@
class DataIBGE
+ attr_accessor :table_code, :date, :variable, :location, :classification,
+ :unit, :value, :periodicity
+
def initialize(table_code, date, variable, location, classification, unit, value, periodicity)
@table_code = table_code
@date = standardize_date(date, periodicity)
@variable = variable
@location = location
@@ -11,59 +14,29 @@
@unit = unit
@value = value
#The standard is:
# 2 : "Mês"
- # 4 : "Trimestral Móvel"
+ # 4 : "Trimestre"
# 5 : "Ano"
+ # 6 : "Trimestre Módel"
@periodicity = periodicity
end
def standardize_date(date, periodicity)
#date is a four digit number
if periodicity == 5 then
return "01/01/#{date}"
- elsif periodicity == 4 or periodicity == 2 then
+
+ elsif [2, 4, 6].include?(periodicity) then
y = date[0..3]
m = date[4..5]
return "01/#{m}/#{y}"
else
puts "\nError parsing date for DataIBGE. Attempted to parse #{date}.\n"
return "ERROR"
end
- end
-
- def table_code
- return @table_code
- end
-
- def date
- return @date
- end
-
- def variable
- return @variable
- end
-
- def location
- return @location
- end
-
- def classification
- return @classification
- end
-
- def unit
- return @unit
- end
-
- def value
- return @value.to_f
- end
-
- def periodicity
- return @periodicity
end
def is_valid?
if @table_code == '' or @table_code == nil or @table_code.to_i <= 0 then
puts "Invalid table code supplied. Value is #{@table_code}."