Class: DataIBGE
- Inherits:
-
Object
- Object
- DataIBGE
- Defined in:
- lib/eia/data.rb
Instance Method Summary collapse
- #classification ⇒ Object
- #date ⇒ Object
-
#initialize(table_code, date, variable, location, classification, unit, value, periodicity) ⇒ DataIBGE
constructor
A new instance of DataIBGE.
- #is_valid? ⇒ Boolean
- #location ⇒ Object
- #periodicity ⇒ Object
- #standardize_date(date, periodicity) ⇒ Object
- #table_code ⇒ Object
- #unit ⇒ Object
- #value ⇒ Object
- #variable ⇒ Object
Constructor Details
#initialize(table_code, date, variable, location, classification, unit, value, periodicity) ⇒ DataIBGE
Returns a new instance of DataIBGE.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/eia/data.rb', line 2 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 : "Trimestral Móvel" # 5 : "Ano" @periodicity = periodicity end |
Instance Method Details
#classification ⇒ Object
52 53 54 |
# File 'lib/eia/data.rb', line 52 def classification return @classification end |
#date ⇒ Object
40 41 42 |
# File 'lib/eia/data.rb', line 40 def date return @date end |
#is_valid? ⇒ Boolean
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/eia/data.rb', line 68 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 > 5 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 |
#location ⇒ Object
48 49 50 |
# File 'lib/eia/data.rb', line 48 def location return @location end |
#periodicity ⇒ Object
64 65 66 |
# File 'lib/eia/data.rb', line 64 def periodicity return @periodicity end |
#standardize_date(date, periodicity) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eia/data.rb', line 21 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 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 |
#table_code ⇒ Object
36 37 38 |
# File 'lib/eia/data.rb', line 36 def table_code return @table_code end |
#unit ⇒ Object
56 57 58 |
# File 'lib/eia/data.rb', line 56 def unit return @unit end |
#value ⇒ Object
60 61 62 |
# File 'lib/eia/data.rb', line 60 def value return @value.to_f end |
#variable ⇒ Object
44 45 46 |
# File 'lib/eia/data.rb', line 44 def variable return @variable end |