Skip to content

Commit

Permalink
feature: Add dashboard worksheet overview methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Drowze committed Aug 9, 2020
1 parent 779a237 commit 4e0b49f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/aspire_budget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'worksheets/backend_data'
require 'worksheets/transactions'
require 'worksheets/category_transfers'
require 'worksheets/dashboard'

require 'models/transaction'
require 'models/category_transfer'
Expand Down
49 changes: 49 additions & 0 deletions lib/worksheets/dashboard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

require 'worksheets/worksheet_base'

module AspireBudget
module Worksheets
class Dashboard < WorksheetBase
WS_TITLE = 'Dashboard'

CELL_MAP_3_2_0 = {
available_to_budget: 'H2',
spent_this_month: 'I2',
budgeted_this_month: 'K2',
pending_transactions: 'O2'
}.freeze

CELL_MAP_3_1_0 = {
available_to_budget: 'C5',
spent_this_month: 'C6',
pending_transactions: 'C7'
}.freeze

IMMEDIATE_METHODS = (CELL_MAP_3_2_0.keys | CELL_MAP_3_1_0.keys)

private_constant :IMMEDIATE_METHODS

IMMEDIATE_METHODS.each do |data_name|
define_method data_name do
cell = cell_map[data_name] || raise("#{data_name} is not supported on #{spreadsheet_version}")
ws.numeric_value(cell)
end
end

private

def cell_map
case spreadsheet_version
when '3.2.0' then CELL_MAP_3_2_0
when '3.1.0' then CELL_MAP_3_1_0
else raise "version #{version} not supported"
end
end

def ws_title
'Dashboard'
end
end
end
end
7 changes: 7 additions & 0 deletions spec/fixtures/v3-1-0/dashboard_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"currency": [
[5, 3],
[6, 3],
[7, 3]
]
}
8 changes: 8 additions & 0 deletions spec/fixtures/v3-2-0/dashboard_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"currency": [
[2, 8],
[2, 9],
[2, 11],
[2, 15]
]
}
33 changes: 33 additions & 0 deletions spec/worksheets/dashboard_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

RSpec.describe AspireBudget::Worksheets::Dashboard do
context 'when on 3.2.0' do
describe 'immediate methods' do
before { use_spreadsheet_version 'v3-2-0' }

it 'returns the expected values' do
expect(subject.available_to_budget).to eq 11505.0
expect(subject.spent_this_month).to eq 0.0
expect(subject.budgeted_this_month).to eq 0.0
expect(subject.pending_transactions).to eq 0.0
end
end
end


context 'when on 3.1.0' do
describe 'immediate methods' do
before { use_spreadsheet_version 'v3-1-0' }

it 'returns the expected values' do
expect(subject.available_to_budget).to eq -495.00 # TODO: fix inconsistency
expect(subject.spent_this_month).to eq 0.0
expect(subject.pending_transactions).to eq 0.0
end

it 'raises on unavailable methods' do
expect { subject.budgeted_this_month }.to raise_error 'budgeted_this_month is not supported on 3.1.0'
end
end
end
end

0 comments on commit 4e0b49f

Please sign in to comment.