From 2478f6c44177b2746e1ef3f27e2918ae0d76b7b4 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 11 Jan 2020 15:25:39 -0500 Subject: [PATCH] Transforming a json now, eh --- .rubocop_todo.yml | 2 +- cpi_fetcher.rb | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b62b271..102c2cf 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-01-09 20:09:37 -0500 using RuboCop version 0.78.0. +# on 2020-01-11 15:25:31 -0500 using RuboCop version 0.78.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 diff --git a/cpi_fetcher.rb b/cpi_fetcher.rb index 08082bd..4021259 100644 --- a/cpi_fetcher.rb +++ b/cpi_fetcher.rb @@ -11,19 +11,17 @@ class CPIFetcher resp = fetch_raw_response return nil unless resp['Results']['series'] - data = resp['Results']['series'].first['data'] - { - start: start_cpi_value(data), - latest: latest_cpi_value(data) - } + resp['Results']['series'].first['data'] end def cpi_csv - values = cpi CSV.generate do |csv| - csv << %w[year value] - csv << [start_year, values.fetch(:start)] - csv << [end_year, values.fetch(:latest)] + csv << %w[year period period_name value] + cpi.each do |rec| + csv << %w[ + year period periodName value + ].map { |k| rec.fetch(k) } + end end end