Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert to JSON, not to Ruby hash #26

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/sheet_zoukas/data_converter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'json'

module SheetZoukas
# convert spreadsheet data to JSON
class DataConverter
Expand All @@ -13,7 +15,7 @@ def convert

@rows.map do |row|
@headers.zip(row).to_h
end
end.to_json
end

private
Expand Down
59 changes: 30 additions & 29 deletions spec/sheet_zoukas/data_converter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'json'
require 'spec_helper'
require 'sheet_zoukas/data_converter'

Expand Down Expand Up @@ -86,41 +87,41 @@
ret = dc.convert

expect(ret).to eq([
{ 'Place' => 'Slice Brothers',
'Deal' => '2 slices for $5.99',
'Deal Earned' => '',
'Deal Used' => '03/30/2024',
'Deal Starts' => '',
'Deal Ends' => '',
'Notes' => 'no longer active',
'Money Saved' => '4.99',
'Reward Type' => 'no longer active' },
{ 'Place' => 'Slice Brothers',
'Deal' => '2 slices for $5.99',
'Deal Earned' => '',
'Deal Used' => '04/11/2024',
'Deal Starts' => '',
'Deal Ends' => '',
'Notes' => 'no longer active',
'Money Saved' => '4.99',
'Reward Type' => 'no longer active' },
{ 'Place' => 'Pot Belly',
'Deal' => '1 free sandwich with the purchase of sandwich between 04/01 and 04/07',
'Deal Earned' => '04/04/2024',
'Deal Used' => '04/08/2024',
'Deal Starts' => '04/01/2024',
'Deal Ends' => '04/07/2024',
'Notes' => '',
'Money Saved' => '10.66',
'Reward Type' => 'rewards' }
])
{ 'Place' => 'Slice Brothers',
'Deal' => '2 slices for $5.99',
'Deal Earned' => '',
'Deal Used' => '03/30/2024',
'Deal Starts' => '',
'Deal Ends' => '',
'Notes' => 'no longer active',
'Money Saved' => '4.99',
'Reward Type' => 'no longer active' },
{ 'Place' => 'Slice Brothers',
'Deal' => '2 slices for $5.99',
'Deal Earned' => '',
'Deal Used' => '04/11/2024',
'Deal Starts' => '',
'Deal Ends' => '',
'Notes' => 'no longer active',
'Money Saved' => '4.99',
'Reward Type' => 'no longer active' },
{ 'Place' => 'Pot Belly',
'Deal' => '1 free sandwich with the purchase of sandwich between 04/01 and 04/07',
'Deal Earned' => '04/04/2024',
'Deal Used' => '04/08/2024',
'Deal Starts' => '04/01/2024',
'Deal Ends' => '04/07/2024',
'Notes' => '',
'Money Saved' => '10.66',
'Reward Type' => 'rewards' }
].to_json)
end

it 'handles empty sheet' do
dc = described_class.new([[], []])
ret = dc.convert

expect(ret).to eq([{}])
expect(ret).to eq([{}].to_json)
end
end
end
20 changes: 11 additions & 9 deletions spec/sheet_zoukas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@
it 'retrieves sheet data' do # rubocop:disable RSpec/ExampleLength
VCR.use_cassette('retrieve_sheet_json') do
data = described_class.retrieve_sheet_json(ENV.fetch('GOOGLE_API_SPREADSHEET_ID_TEST', nil), 'Log')
expect(data[0]).to eq('Place' => 'Slice Brothers',
'Deal' => '2 slices for $5.99',
'Deal Earned' => '',
'Deal Used' => '03/30',
'Deal Starts' => '',
'Deal Ends' => '',
'Notes' => 'no longer active',
'Money Saved' => '4.99',
'Reward Type' => 'no longer active')

expect(data).to include({ 'Place' => 'Slice Brothers',
'Deal' => '2 slices for $5.99',
'Deal Earned' => '',
'Deal Used' => '03/30',
'Deal Starts' => '',
'Deal Ends' => '',
'Notes' => 'no longer active',
'Money Saved' => '4.99',
'Reward Type' => 'no longer active' }.to_json)
end
end

it 'fails when missing required environment variable' do # rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
missing = SheetZoukas::REQUIRED_VARS.first
ENV.delete(missing)

expect do
expect do
described_class.retrieve_sheet_json(ENV.fetch('GOOGLE_API_SPREADSHEET_ID_TEST', nil), 'Log')
Expand Down