mudrat_projector 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mudrat_projector/projector.rb +47 -4
- data/lib/mudrat_projector/scheduled_transaction.rb +2 -2
- data/lib/mudrat_projector/version.rb +1 -1
- data/test/{models → lib}/accounts_test.rb +0 -0
- data/test/{models → lib}/chart_of_accounts_test.rb +0 -0
- data/test/{models → lib}/date_diff_test.rb +0 -0
- data/test/{models → lib}/projection_test.rb +0 -0
- data/test/{models → lib}/projector_test.rb +51 -0
- data/test/{models → lib}/schedule_test.rb +0 -0
- data/test/{models → lib}/scheduled_transaction_test.rb +0 -0
- data/test/{models → lib}/tax_calculator_test.rb +0 -0
- data/test/{models → lib}/transaction_entry_test.rb +0 -0
- data/test/{models → lib}/transaction_handler_test.rb +0 -0
- data/test/{models → lib}/transaction_test.rb +0 -0
- data/test/{models → lib}/validator_test.rb +0 -0
- metadata +26 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cce3469b96fb8c1678dac9ea4eef337229ac064
|
4
|
+
data.tar.gz: 41ca2ea8737e746fe8d4836816191ba52d209d79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8144c435f0b81475f317f4dda0ffe7f5970a83a7f8fd14c2b6eb4308b5d2eacf136daea5e0ea77e1623dad57bf1accc5e7d8228f389f126dc671aa62fc1856b
|
7
|
+
data.tar.gz: cbe2e1250bad94129a09cd49e6ba3f8ae4e87f74f5eb811157790a578f134ebf72de2ba0513878927cb59a23ac0bbdd4b1e3fd30551be5b5809d01b0475ee9c8
|
@@ -15,6 +15,7 @@ module MudratProjector
|
|
15
15
|
@chart = params.fetch :chart, ChartOfAccounts.new
|
16
16
|
@from = params.fetch :from, ABSOLUTE_START
|
17
17
|
@transactions = []
|
18
|
+
@transaction_with_ids = {}
|
18
19
|
@validator = Validator.new projector: self, chart: @chart
|
19
20
|
end
|
20
21
|
|
@@ -39,14 +40,46 @@ module MudratProjector
|
|
39
40
|
def add_transaction params
|
40
41
|
if params.is_a? Transaction
|
41
42
|
transaction = params
|
43
|
+
elsif id = params.delete(:id)
|
44
|
+
return add_transaction_with_id(id, params)
|
42
45
|
else
|
43
|
-
|
44
|
-
transaction = klass.new params
|
45
|
-
validate_transaction! transaction
|
46
|
+
transaction = build_transaction params
|
46
47
|
end
|
47
48
|
@transactions.push transaction
|
48
49
|
end
|
49
50
|
|
51
|
+
def add_transaction_with_id(id, params)
|
52
|
+
@transaction_with_ids[id] = build_transaction params
|
53
|
+
end
|
54
|
+
|
55
|
+
def alter_transaction(id, effective_date: nil, scale: nil)
|
56
|
+
orig = remove_transaction id
|
57
|
+
old, new = orig.slice(effective_date - 1)
|
58
|
+
old.each do |t| add_transaction t; end
|
59
|
+
unless scale == 0
|
60
|
+
new_transaction = new.clone_transaction multiplier: scale
|
61
|
+
add_transaction_with_id id, new_transaction
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def fetch_transaction(id)
|
66
|
+
@transaction_with_ids.fetch id
|
67
|
+
end
|
68
|
+
|
69
|
+
def remove_transaction(id)
|
70
|
+
@transaction_with_ids.fetch id # generate KeyError
|
71
|
+
@transaction_with_ids.delete id
|
72
|
+
end
|
73
|
+
|
74
|
+
def end_scheduled_transaction(id, effective_date: nil)
|
75
|
+
alter_transaction id, effective_date: (effective_date + 1), scale: 0
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_transaction(&block)
|
79
|
+
@transactions.each &block
|
80
|
+
@transaction_with_ids.values.each(&block)
|
81
|
+
end
|
82
|
+
|
50
83
|
def balanced?
|
51
84
|
balance.zero?
|
52
85
|
end
|
@@ -62,7 +95,7 @@ module MudratProjector
|
|
62
95
|
if build_next
|
63
96
|
handler.next_projector = self.class.new from: to + 1, chart: @chart
|
64
97
|
end
|
65
|
-
|
98
|
+
each_transaction do |transaction| handler << transaction; end
|
66
99
|
projection.project! &block
|
67
100
|
handler.next_projector
|
68
101
|
end
|
@@ -71,5 +104,15 @@ module MudratProjector
|
|
71
104
|
transactions.each do |transaction| add_transaction transaction; end
|
72
105
|
end
|
73
106
|
|
107
|
+
private
|
108
|
+
|
109
|
+
def build_transaction params
|
110
|
+
return params if params.is_a? Transaction
|
111
|
+
klass = params.has_key?(:schedule) ? ScheduledTransaction : Transaction
|
112
|
+
klass.new(params).tap do |transaction|
|
113
|
+
validate_transaction! transaction
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
74
117
|
end
|
75
118
|
end
|
@@ -9,11 +9,11 @@ module MudratProjector
|
|
9
9
|
|
10
10
|
def build_transactions intervals
|
11
11
|
intervals.map do |date, prorate|
|
12
|
-
clone_transaction new_date: date, multiplier: prorate
|
12
|
+
clone_transaction new_date: date, multiplier: prorate, new_schedule: nil
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def clone_transaction new_date: date, new_schedule:
|
16
|
+
def clone_transaction new_date: date, new_schedule: schedule.serialize, multiplier: 1
|
17
17
|
params = build_cloned_tranasction_params new_date, multiplier
|
18
18
|
return Transaction.new(params) if new_schedule.nil?
|
19
19
|
params[:schedule] = new_schedule
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -151,6 +151,57 @@ class ProjectorTransactionTest < Minitest::Test
|
|
151
151
|
assert_equal 1500000, @projector.net_worth
|
152
152
|
end
|
153
153
|
|
154
|
+
def test_add_and_remove_transaction_with_id
|
155
|
+
@projector.add_transaction(
|
156
|
+
id: :foo,
|
157
|
+
date: jan_2_2000,
|
158
|
+
credit: { amount: 1000, account_id: :nustartup_inc },
|
159
|
+
debit: { amount: 1000, account_id: :checking },
|
160
|
+
)
|
161
|
+
|
162
|
+
refute_nil @projector.fetch_transaction(:foo)
|
163
|
+
|
164
|
+
@projector.remove_transaction(:foo)
|
165
|
+
|
166
|
+
assert_raises KeyError do
|
167
|
+
@projector.fetch_transaction(:foo)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_ending_scheduled_transaction
|
172
|
+
@projector.add_transaction(
|
173
|
+
id: :bar,
|
174
|
+
date: jan_1_2000,
|
175
|
+
credit: { amount: 1000, account_id: :nustartup_inc },
|
176
|
+
debit: { amount: 1000, account_id: :checking },
|
177
|
+
schedule: every_month,
|
178
|
+
)
|
179
|
+
|
180
|
+
@projector.end_scheduled_transaction :bar, effective_date: jun_30_2000
|
181
|
+
@projector.project to: dec_31_2000
|
182
|
+
|
183
|
+
assert_equal 6000, @projector.net_worth
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_altering_scheduled_transaction
|
187
|
+
@projector.add_transaction(
|
188
|
+
id: :bar,
|
189
|
+
date: jan_1_2000,
|
190
|
+
credit: { amount: 1000, account_id: :nustartup_inc },
|
191
|
+
debit: { amount: 1000, account_id: :checking },
|
192
|
+
schedule: every_month,
|
193
|
+
)
|
194
|
+
|
195
|
+
@projector.alter_transaction(
|
196
|
+
:bar,
|
197
|
+
effective_date: jul_1_2000,
|
198
|
+
scale: 2.0,
|
199
|
+
)
|
200
|
+
|
201
|
+
@projector.project to: dec_31_2000
|
202
|
+
assert_equal (6000 + 12000), @projector.net_worth
|
203
|
+
end
|
204
|
+
|
154
205
|
private
|
155
206
|
|
156
207
|
def add_scheduled_transaction date = jan_1_2000
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mudrat_projector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ntl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,18 +145,18 @@ files:
|
|
145
145
|
- test/integrations/long_term_projection_test.rb
|
146
146
|
- test/integrations/mortgage_test.rb
|
147
147
|
- test/integrations/self_employed_tax_calculation_test.rb
|
148
|
-
- test/
|
149
|
-
- test/
|
150
|
-
- test/
|
151
|
-
- test/
|
152
|
-
- test/
|
153
|
-
- test/
|
154
|
-
- test/
|
155
|
-
- test/
|
156
|
-
- test/
|
157
|
-
- test/
|
158
|
-
- test/
|
159
|
-
- test/
|
148
|
+
- test/lib/accounts_test.rb
|
149
|
+
- test/lib/chart_of_accounts_test.rb
|
150
|
+
- test/lib/date_diff_test.rb
|
151
|
+
- test/lib/projection_test.rb
|
152
|
+
- test/lib/projector_test.rb
|
153
|
+
- test/lib/schedule_test.rb
|
154
|
+
- test/lib/scheduled_transaction_test.rb
|
155
|
+
- test/lib/tax_calculator_test.rb
|
156
|
+
- test/lib/transaction_entry_test.rb
|
157
|
+
- test/lib/transaction_handler_test.rb
|
158
|
+
- test/lib/transaction_test.rb
|
159
|
+
- test/lib/validator_test.rb
|
160
160
|
- test/test_helper.rb
|
161
161
|
homepage: https://github.com/ntl/mudrat-projector
|
162
162
|
licenses:
|
@@ -187,16 +187,16 @@ test_files:
|
|
187
187
|
- test/integrations/long_term_projection_test.rb
|
188
188
|
- test/integrations/mortgage_test.rb
|
189
189
|
- test/integrations/self_employed_tax_calculation_test.rb
|
190
|
-
- test/
|
191
|
-
- test/
|
192
|
-
- test/
|
193
|
-
- test/
|
194
|
-
- test/
|
195
|
-
- test/
|
196
|
-
- test/
|
197
|
-
- test/
|
198
|
-
- test/
|
199
|
-
- test/
|
200
|
-
- test/
|
201
|
-
- test/
|
190
|
+
- test/lib/accounts_test.rb
|
191
|
+
- test/lib/chart_of_accounts_test.rb
|
192
|
+
- test/lib/date_diff_test.rb
|
193
|
+
- test/lib/projection_test.rb
|
194
|
+
- test/lib/projector_test.rb
|
195
|
+
- test/lib/schedule_test.rb
|
196
|
+
- test/lib/scheduled_transaction_test.rb
|
197
|
+
- test/lib/tax_calculator_test.rb
|
198
|
+
- test/lib/transaction_entry_test.rb
|
199
|
+
- test/lib/transaction_handler_test.rb
|
200
|
+
- test/lib/transaction_test.rb
|
201
|
+
- test/lib/validator_test.rb
|
202
202
|
- test/test_helper.rb
|