twobook 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/twobook/account_query.rb +9 -9
- data/lib/twobook/corrections.rb +1 -1
- data/lib/twobook/handler/query_helpers.rb +1 -1
- data/lib/twobook/helpers.rb +28 -0
- data/lib/twobook/version.rb +1 -1
- data/lib/twobook.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8677b9416590ac7c8c6ca8de3404915d546ec4f
|
4
|
+
data.tar.gz: 58b905e2f7df29c1c96b8a5d21f77a9cda0ed726
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85dbbba2586a8d6f3f0f6faa27d87c44e3b64ef32bdd71a57b54d0ca8544f024d548f28c8eef5145136ebbc1b5dc203e3760b1005eb736eaceac74a5ea79c0d3
|
7
|
+
data.tar.gz: a9f9c5db7b55ca919276184086b0115a31754e531b09aab80f6ded3faec8f93ca353dbf91600a21c28d4182a42117445e4a96a1a33ad37f10b4afdc4481df751
|
@@ -9,7 +9,7 @@ module Twobook
|
|
9
9
|
false
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def on(array)
|
13
13
|
array
|
14
14
|
end
|
15
15
|
|
@@ -48,7 +48,7 @@ module Twobook
|
|
48
48
|
end
|
49
49
|
|
50
50
|
class NoneQuery < AccountQuery
|
51
|
-
def
|
51
|
+
def on(_)
|
52
52
|
[]
|
53
53
|
end
|
54
54
|
|
@@ -88,8 +88,8 @@ module Twobook
|
|
88
88
|
@child_query.none?
|
89
89
|
end
|
90
90
|
|
91
|
-
def
|
92
|
-
@child_query.
|
91
|
+
def on(array)
|
92
|
+
@child_query.on(array).select do |account|
|
93
93
|
next unless matches_attributes(account)
|
94
94
|
next unless matches_class(account)
|
95
95
|
next unless matches_data(account)
|
@@ -166,7 +166,7 @@ module Twobook
|
|
166
166
|
@account
|
167
167
|
end
|
168
168
|
|
169
|
-
def
|
169
|
+
def on(accounts)
|
170
170
|
accounts.select { |account| account.name == @name }
|
171
171
|
end
|
172
172
|
end
|
@@ -179,8 +179,8 @@ module Twobook
|
|
179
179
|
@second = second
|
180
180
|
end
|
181
181
|
|
182
|
-
def
|
183
|
-
@first.
|
182
|
+
def on(array)
|
183
|
+
@first.on(array) & @second.on(array)
|
184
184
|
end
|
185
185
|
|
186
186
|
def none?
|
@@ -200,8 +200,8 @@ module Twobook
|
|
200
200
|
@first.none? && @second.none?
|
201
201
|
end
|
202
202
|
|
203
|
-
def
|
204
|
-
@first.
|
203
|
+
def on(array)
|
204
|
+
@first.on(array) | @second.on(array)
|
205
205
|
end
|
206
206
|
end
|
207
207
|
end
|
data/lib/twobook/corrections.rb
CHANGED
@@ -49,7 +49,7 @@ module Twobook
|
|
49
49
|
correct_accounts = self.class.simulate_correction(corrected_events, account_snapshots)
|
50
50
|
|
51
51
|
correct_accounts.each do |correct|
|
52
|
-
original = where(name: correct.name).
|
52
|
+
original = where(name: correct.name).on(@accounts_in_process).first
|
53
53
|
adjust_original_account_balance(original, correct)
|
54
54
|
adjust_original_account_data(original, correct)
|
55
55
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Twobook
|
2
|
+
def self.where(**conditions)
|
3
|
+
AccountQuery.where(**conditions)
|
4
|
+
end
|
5
|
+
|
6
|
+
module Helpers
|
7
|
+
def expect_account_balances(accounts, table)
|
8
|
+
table.each_slice(2) do |name_or_category, total_balance|
|
9
|
+
query, reason = (
|
10
|
+
if name_or_category =~ /:/
|
11
|
+
[
|
12
|
+
Twobook::AccountQuery.where(name: name_or_category),
|
13
|
+
"expected balance of account \"#{name_or_category}\" to be #{total_balance}, got %s",
|
14
|
+
]
|
15
|
+
else
|
16
|
+
[
|
17
|
+
Twobook::AccountQuery.where(category: name_or_category),
|
18
|
+
"expected sum of accounts in category \"#{name_or_category}\" to be #{total_balance}, got %s",
|
19
|
+
]
|
20
|
+
end
|
21
|
+
)
|
22
|
+
|
23
|
+
balance = query.on(accounts).map(&:balance).sum
|
24
|
+
expect(balance).to be_within(0.01).of(total_balance), format(reason, balance)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/twobook/version.rb
CHANGED
data/lib/twobook.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twobook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parry
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/twobook/handler.rb
|
124
124
|
- lib/twobook/handler/booking_helpers.rb
|
125
125
|
- lib/twobook/handler/query_helpers.rb
|
126
|
+
- lib/twobook/helpers.rb
|
126
127
|
- lib/twobook/number_handling.rb
|
127
128
|
- lib/twobook/serialization.rb
|
128
129
|
- lib/twobook/utilities.rb
|