-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Add dashboard worksheet overview methods
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"currency": [ | ||
[5, 3], | ||
[6, 3], | ||
[7, 3] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"currency": [ | ||
[2, 8], | ||
[2, 9], | ||
[2, 11], | ||
[2, 15] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |