Class: DataIBGE
- Inherits:
-
Object
- Object
- DataIBGE
- Defined in:
- lib/eia/data.rb
Instance Attribute Summary collapse
-
#classification ⇒ Object
Returns the value of attribute classification.
-
#date ⇒ Object
Returns the value of attribute date.
-
#location ⇒ Object
Returns the value of attribute location.
-
#periodicity ⇒ Object
Returns the value of attribute periodicity.
-
#table_code ⇒ Object
Returns the value of attribute table_code.
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#value ⇒ Object
Returns the value of attribute value.
-
#variable ⇒ Object
Returns the value of attribute variable.
Instance Method Summary collapse
-
#initialize(table_code, date, variable, location, classification, unit, value, periodicity) ⇒ DataIBGE
constructor
A new instance of DataIBGE.
- #is_valid? ⇒ Boolean
- #standardize_date(date, periodicity) ⇒ Object
Constructor Details
#initialize(table_code, date, variable, location, classification, unit, value, periodicity) ⇒ DataIBGE
Returns a new instance of DataIBGE.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/eia/data.rb', line 5 def initialize(table_code, date, variable, location, classification, unit, value, periodicity) @table_code = table_code @date = standardize_date(date, periodicity) @variable = variable @location = location #is an array @classification = classification @unit = unit @value = value #The standard is: # 2 : "Mês" # 4 : "Trimestre" # 5 : "Ano" # 6 : "Trimestre Módel" @periodicity = periodicity end |
Instance Attribute Details
#classification ⇒ Object
Returns the value of attribute classification.
2 3 4 |
# File 'lib/eia/data.rb', line 2 def classification @classification end |
#date ⇒ Object
Returns the value of attribute date.
2 3 4 |
# File 'lib/eia/data.rb', line 2 def date @date end |
#location ⇒ Object
Returns the value of attribute location.
2 3 4 |
# File 'lib/eia/data.rb', line 2 def location @location end |
#periodicity ⇒ Object
Returns the value of attribute periodicity.
2 3 4 |
# File 'lib/eia/data.rb', line 2 def periodicity @periodicity end |
#table_code ⇒ Object
Returns the value of attribute table_code.
2 3 4 |
# File 'lib/eia/data.rb', line 2 def table_code @table_code end |
#unit ⇒ Object
Returns the value of attribute unit.
2 3 4 |
# File 'lib/eia/data.rb', line 2 def unit @unit end |
#value ⇒ Object
Returns the value of attribute value.
2 3 4 |
# File 'lib/eia/data.rb', line 2 def value @value end |
#variable ⇒ Object
Returns the value of attribute variable.
2 3 4 |
# File 'lib/eia/data.rb', line 2 def variable @variable end |
Instance Method Details
#is_valid? ⇒ Boolean
41 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 78 79 80 81 82 83 |
# File 'lib/eia/data.rb', line 41 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}." return false end if @date == '' or @date == "ERROR" or @date == nil then puts "Date found is invalid. Value is '#{@date}'." return false end if @variable == '' or @variable == nil then puts "Variable found is invalid. Value is '#{@variable}'." return false end if @location == '' or @location == nil then puts "Location found is invalid. Value is '#{@location}'." return false end if @unit == '' or @unit == nil then puts "Unit found is invalid. Value is '#{@unit}'." return false end if @periodicity == nil or @periodicity.to_i > 6 or @periodicity.to_i < 0 then puts "Periodicity is invalid. Value is '#{@periodicity}'." return false end if @value == '' or @value == nil then puts "Value found is invalid. Value is '#{@value}'." return false end if @classification == nil or not @classification.class.to_s.eql? "Array" then puts "Classification is invalid. Value is nil." return false end return true end |
#standardize_date(date, periodicity) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/eia/data.rb', line 25 def standardize_date(date, periodicity) #date is a four digit number if periodicity == 5 then return "01/01/#{date}" 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 |