class CPIU::Data
Return CPI data to the user while stripping the rest of the response data returned by the server
Public Class Methods
cpiu_month(year, month)
click to toggle source
Get CPI value for a given month and year @param year [Integer] the year @param month [Integer] the month (1-12) @return [Float]
# File lib/cpiu/data.rb, line 52 def self.cpiu_month(year, month) data = CPIU::Data.single_year(year).reverse data[month - 1]['value'].to_f end
cpiu_year(year)
click to toggle source
Get annual average CPI for a given year @param year [Integer] the year @return [Float]
# File lib/cpiu/data.rb, line 43 def self.cpiu_year(year) data = CPIU::Data.single_year(year) data[0]['value'].to_f end
single_year(year)
click to toggle source
Get CPI data for a single year @param year [Integer] @return [Array<Hash>] an array of hashes containing monthly CPI values
# File lib/cpiu/data.rb, line 26 def self.single_year(year) response = CPIU::API.request_data(year, year, true) response['Results']['series'][0]['data'] end
year_range(startyear, endyear)
click to toggle source
Get CPI data for a year range (up to 20 years) @param startyear [Integer] the first year to get data for @param endyear [Integer] the last year to get data for @return [Array<Hash>] an array of hashes containing monthly CPI values
# File lib/cpiu/data.rb, line 35 def self.year_range(startyear, endyear) response = CPIU::API.request_data(startyear, endyear) response['Results']['series'][0]['data'] end