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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 821400fab063ba0c19515c146c267e7b2fb934a5
4
- data.tar.gz: 76a76e0812bfee424e16523da971fbe0c409438c
3
+ metadata.gz: d8677b9416590ac7c8c6ca8de3404915d546ec4f
4
+ data.tar.gz: 58b905e2f7df29c1c96b8a5d21f77a9cda0ed726
5
5
  SHA512:
6
- metadata.gz: 9666b1a26e7eaaf9e10e5d8d893141c40166ceaaab4ce326caa15ef8ef7b98fd9538e3ba5ead40951dba1f1273eb26a1c951174f1d22147e9da145813abf36a3
7
- data.tar.gz: 0874b4b4aed90a687f3e2c94270d63cb46134636a3db54b27d226bcd87296898dc383504f974832ba917960af3a2009f744e9e0b89c893e46403a70686d2cda8
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 execute(array)
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 execute(_)
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 execute(array)
92
- @child_query.execute(array).select do |account|
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 execute(accounts)
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 execute(array)
183
- @first.execute(array) & @second.execute(array)
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 execute(array)
204
- @first.execute(array) | @second.execute(array)
203
+ def on(array)
204
+ @first.on(array) | @second.on(array)
205
205
  end
206
206
  end
207
207
  end
@@ -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).execute(@accounts_in_process).first
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
@@ -21,7 +21,7 @@ module Twobook
21
21
  end
22
22
 
23
23
  def satisfy_requirement(requested:, query:)
24
- accounts = query.execute(@accounts_in_process)
24
+ accounts = query.on(@accounts_in_process)
25
25
 
26
26
  case requested
27
27
  when :one
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Twobook
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/twobook.rb CHANGED
@@ -17,3 +17,4 @@ require 'twobook/agreement'
17
17
  require 'twobook/event_processing'
18
18
  require 'twobook/corrections'
19
19
  require 'twobook/serialization'
20
+ require 'twobook/helpers'
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.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