Sha256: d6a5dafa34f64323370242d0ebcbd03ef54410102bac8bb71e3c25b22722ce92

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

# CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
# Copyright (C) 2017 Cody Logan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

require 'cpiu/api'

module CPIU
  # Return CPI data to the user while stripping the rest
  # of the response data returned by the server
  class Data
    # Get CPI data for a single year
    # @param year [Integer]
    # @return [Array<Hash>] an array of hashes containing monthly CPI values
    def self.single_year(year)
      response = CPIU::API.request_data(year, year)
      response['Results']['series'][0]['data']
    end

    # 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
    def self.year_range(startyear, endyear)
      response = CPIU::API.request_data(startyear, endyear)
      response['Results']['series'][0]['data']
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cpiu-0.1.1 lib/cpiu/data.rb
cpiu-0.1.0 lib/cpiu/data.rb