uk_account_validator 0.0.5 → 0.0.6

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: 72c9a0ad1d2060616cecd95633d65e00465cc5c3
4
- data.tar.gz: e000a86c002c5c869e70594fd6df4d00e73e8a00
3
+ metadata.gz: 06b6904edebd4d278f6e985ec8f8393bb2553c4a
4
+ data.tar.gz: 52648d7abd5a27a2ee24e82d870e524c5a15b4b3
5
5
  SHA512:
6
- metadata.gz: cce9293340964b404053561439ca77ce80d99e3df787269f00920b22cd8e3f27a0286483d348b5de3021c65a6b4939e416396cdade37159391d35194ea7acb8a
7
- data.tar.gz: a4ae9458a37d0bd2c3164fa13574c65bd924c5b53259e114c8f46eac814164d8c84bb0723aea6fa36e9783f3eb8525315372f22f328176077eb774fe26be1e5d
6
+ metadata.gz: 80627f545c2d711fac360c6fa954c160ba320eba4bb4038279f4df0e5aa4c3b517012604e3154d534459536b46c31decbdc564537a4d14514d3c827e4f2f49cc
7
+ data.tar.gz: 8b9f289f57826746f929394d13c2a85ac5686d21e70d8763d057a6c1258ce19de57057ba67d6cec1aeef2914d05d08225b09957b69136e8e2cd75ca0d8de3739
@@ -5,6 +5,8 @@ rvm:
5
5
  - 2.0.0
6
6
  - 2.1.6
7
7
  - 2.2.1
8
+ - 2.3.4
9
+ - 2.4.1
8
10
 
9
11
  bundler_args: --without development
10
12
 
@@ -1,3 +1,5 @@
1
+ require 'uk_account_validator/backports/array_bsearch_index'
2
+
1
3
  require 'uk_account_validator/number_indices.rb'
2
4
  require 'uk_account_validator/validator.rb'
3
5
  require 'uk_account_validator/modulus_weight.rb'
@@ -0,0 +1,33 @@
1
+ # Copied from backports gem
2
+ unless Array.method_defined? :bsearch_index
3
+ class Array
4
+ def bsearch_index
5
+ return to_enum(__method__) unless block_given?
6
+ from = 0
7
+ to = size - 1
8
+ satisfied = nil
9
+ while from <= to do
10
+ midpoint = (from + to).div(2)
11
+ result = yield(self[midpoint])
12
+ case result
13
+ when Numeric
14
+ return midpoint if result == 0
15
+ result = result < 0
16
+ when true
17
+ satisfied = midpoint
18
+ when nil, false
19
+ # nothing to do
20
+ else
21
+ raise TypeError, "wrong argument type #{result.class} (must be numeric, true, false or nil)"
22
+ end
23
+
24
+ if result
25
+ to = midpoint - 1
26
+ else
27
+ from = midpoint + 1
28
+ end
29
+ end
30
+ satisfied
31
+ end
32
+ end
33
+ end
@@ -8,24 +8,28 @@ module UkAccountValidator
8
8
  @weights << ModulusWeight.from_line(line)
9
9
  end
10
10
 
11
- @weights.sort! { |weight| weight.sort_code_start.to_i }
11
+ @weights.sort_by! { |weight| -weight.sort_code_start.to_i }
12
12
  end
13
13
 
14
- def find(sort_code, found_weights = [], exclude = [])
14
+ def find(sort_code)
15
15
  sort_code = sort_code.to_i
16
16
 
17
- weight = @weights.bsearch do |w|
18
- w.sort_code_start.to_i <= sort_code && !exclude.include?(w)
17
+ min_found_weight_index = @weights.bsearch_index do |w|
18
+ w.sort_code_start.to_i <= sort_code
19
19
  end
20
20
 
21
- return found_weights if weight.nil?
22
- return found_weights unless
23
- weight.sort_code_start.to_i <= sort_code &&
24
- sort_code <= weight.sort_code_end.to_i
21
+ return [] if min_found_weight_index.nil?
25
22
 
26
- found_weights << weight
23
+ found_weights = []
24
+ index = min_found_weight_index
25
+ while index < @weights.size &&
26
+ @weights[index].sort_code_start.to_i <= sort_code &&
27
+ sort_code <= @weights[index].sort_code_end.to_i
28
+ found_weights << @weights[index]
29
+ index += 1
30
+ end
27
31
 
28
- find(sort_code, found_weights, exclude + [weight])
32
+ found_weights
29
33
  end
30
34
  end
31
35
  end
@@ -1,3 +1,3 @@
1
1
  module UkAccountValidator
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uk_account_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hayden Ball
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-14 00:00:00.000000000 Z
11
+ date: 2017-08-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Validate UK Account Numbers and Sort Codes
14
14
  email:
@@ -39,6 +39,7 @@ files:
39
39
  - features/support/env.rb
40
40
  - features/two_modulus_check.feature
41
41
  - lib/uk_account_validator.rb
42
+ - lib/uk_account_validator/backports/array_bsearch_index.rb
42
43
  - lib/uk_account_validator/exceptions/base_exception.rb
43
44
  - lib/uk_account_validator/exceptions/exception_1.rb
44
45
  - lib/uk_account_validator/exceptions/exception_10.rb
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  version: '0'
83
84
  requirements: []
84
85
  rubyforge_project:
85
- rubygems_version: 2.5.2
86
+ rubygems_version: 2.6.11
86
87
  signing_key:
87
88
  specification_version: 4
88
89
  summary: Validate UK Account Numbers and Sort Codes