From 2033546272c0dd68f5acc86faaf088247e0d18af Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 30 Aug 2016 10:56:49 -0400 Subject: [PATCH] Doing the maintenance dance --- .rubocop_todo.yml | 11 +++++++- Gemfile | 2 +- Gemfile.lock | 43 ++++++++++++++---------------- cpi_fetcher.rb | 67 +++-------------------------------------------- 4 files changed, 35 insertions(+), 88 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4705069..ab099c4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,7 +1,16 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-10-04 18:16:18 -0400 using RuboCop version 0.34.2. +# on 2016-08-30 10:56:44 -0400 using RuboCop version 0.42.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +Metrics/AbcSize: + Max: 17 + +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 14 diff --git a/Gemfile b/Gemfile index 3b1403c..748d429 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.2.3' if ENV.key?('DYNO') +ruby '2.3.1' if ENV.key?('DYNO') gem 'aws-sdk', '~> 2' gem 'pry', group: %i(development test) diff --git a/Gemfile.lock b/Gemfile.lock index ecc0b5c..8157052 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,37 +1,34 @@ GEM remote: https://rubygems.org/ specs: - ast (2.1.0) - astrolabe (1.3.1) - parser (~> 2.2) - aws-sdk (2.1.20) - aws-sdk-resources (= 2.1.20) - aws-sdk-core (2.1.20) + ast (2.3.0) + aws-sdk (2.5.6) + aws-sdk-resources (= 2.5.6) + aws-sdk-core (2.5.6) jmespath (~> 1.0) - aws-sdk-resources (2.1.20) - aws-sdk-core (= 2.1.20) - coderay (1.1.0) - jmespath (1.0.2) - multi_json (~> 1.0) + aws-sdk-resources (2.5.6) + aws-sdk-core (= 2.5.6) + coderay (1.1.1) + jmespath (1.3.1) method_source (0.8.2) - multi_json (1.11.2) - parser (2.2.2.6) - ast (>= 1.1, < 3.0) + parser (2.3.1.2) + ast (~> 2.2) powerpack (0.1.1) - pry (0.10.1) + pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - rack (1.6.4) - rainbow (2.0.0) - rubocop (0.34.2) - astrolabe (~> 1.3) - parser (>= 2.2.2.5, < 3.0) + rack (2.0.1) + rainbow (2.1.0) + rubocop (0.42.0) + parser (>= 2.3.1.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) - ruby-progressbar (~> 1.4) - ruby-progressbar (1.7.5) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.8.1) slop (3.6.0) + unicode-display_width (1.1.0) PLATFORMS ruby @@ -43,4 +40,4 @@ DEPENDENCIES rubocop BUNDLED WITH - 1.10.6 + 1.12.5 diff --git a/cpi_fetcher.rb b/cpi_fetcher.rb index d0ad966..a612b99 100644 --- a/cpi_fetcher.rb +++ b/cpi_fetcher.rb @@ -5,7 +5,7 @@ require 'net/http' require 'json' class CPIFetcher - DEFAULT_CPI_SERIES_URL = 'http://api.bls.gov/publicAPI/v2/timeseries/data/CUUSA210SA0' + DEFAULT_CPI_SERIES_URL = 'http://api.bls.gov/publicAPI/v2/timeseries/data/CUUSA210SA0'.freeze attr_reader :cpi_series_url def initialize @@ -17,7 +17,9 @@ class CPIFetcher return nil unless resp['Results']['series'] - resp['Results']['series'].first['data'].first['value'] + data = resp['Results']['series'].first['data'] + data.sort! { |a, b| a['year'] <=> b['year'] } + data.last['value'] end private @@ -31,64 +33,3 @@ if $PROGRAM_NAME == __FILE__ puts CPIFetcher.new.cpi exit 0 end - -__END__ -{ - "status": "REQUEST_SUCCEEDED", - "responseTime": 36, - "message": [], - "Results": { - "series": [ - { - "seriesID": "CUUSA210SA0", - "data": [ - { - "year": "2015", - "period": "S01", - "periodName": "1st Half", - "value": "220.381", - "footnotes": [ - {} - ] - }, - { - "year": "2014", - "period": "S02", - "periodName": "2nd Half", - "value": "220.891", - "footnotes": [ - {} - ] - }, - { - "year": "2014", - "period": "S01", - "periodName": "1st Half", - "value": "220.352", - "footnotes": [ - {} - ] - }, - { - "year": "2013", - "period": "S02", - "periodName": "2nd Half", - "value": "217.983", - "footnotes": [ - {} - ] - }, - { - "year": "2013", - "period": "S01", - "periodName": "1st Half", - "value": "216.941", - "footnotes": [ - {} - ] - } - ] - } - ] - } -}