Class: Inegi::Client
Class Method Summary collapse
-
.format_indexes(hash) ⇒ Object
From a hash with Inegifacil’s structure, return a more readable one.
-
.validate_indicator(indicator) ⇒ Object
Validates that an indicator adheres to INEGI’s format It looks like indicators have a format of 10 digits.
-
.validate_location(location) ⇒ Object
Validates that a location adheres to INEGI’s format It looks like locations have a format of 5 digits.
Instance Method Summary collapse
-
#indexes(indicator, location = nil) ⇒ Object
After validating indicator, call Inegifacil’s service and return indexes.
Class Method Details
.format_indexes(hash) ⇒ Object
From a hash with Inegifacil’s structure, return a more readable one
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/inegi_ruby.rb', line 61 def self.format_indexes(hash) result = { indicator: hash["header"]["INDICADOR"] } values = hash["indices"].map do |v| { period: v["TIME_PERIOD"], value: v["OBS_VALUE"], units: v["OBS_UNIT"] } end values = { values: values } result.merge values end |
.validate_indicator(indicator) ⇒ Object
Validates that an indicator adheres to INEGI’s format It looks like indicators have a format of 10 digits
19 20 21 22 |
# File 'lib/inegi_ruby.rb', line 19 def self.validate_indicator(indicator) i_regex = /\A\d{10}\z/ indicator =~ i_regex || raise(ArgumentError.new("Given indicator is not valid")) end |
.validate_location(location) ⇒ Object
Validates that a location adheres to INEGI’s format It looks like locations have a format of 5 digits
32 33 34 35 |
# File 'lib/inegi_ruby.rb', line 32 def self.validate_location(location) l_regex = /\A\d{5}\z/ location =~ l_regex || raise(ArgumentError.new("Given location is not valid")) end |
Instance Method Details
#indexes(indicator, location = nil) ⇒ Object
After validating indicator, call Inegifacil’s service and return indexes.
43 44 45 46 47 48 49 |
# File 'lib/inegi_ruby.rb', line 43 def indexes(indicator, location = nil) self.class.validate_indicator indicator self.class.validate_location location if location path = "/#{indicator}/#{location}" indexes = self.class.get path self.class.format_indexes indexes end |