banktools-se 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c5c3cd7492d627e0bd743ad56328b7d97daad3a
4
- data.tar.gz: e83b11dbab0e65165fcbcf2ed490770624023ea9
3
+ metadata.gz: 2e925fd3ed8cc9466d3349621bbd04324592ef67
4
+ data.tar.gz: 10ae31638c8fb1951f00c9faec6c5d2a14b9ddd3
5
5
  SHA512:
6
- metadata.gz: 173c075e3289cd074802e1b0530b2cfa4dcf11a087bec1bc6f1582252ab44c67d785ebf239e77e14930ec3db646d820098bded4fed99646e136b30fccfed7061
7
- data.tar.gz: 67767a7305bb6425c53200c8e664e9635ce2162c319f70772bd3747a00a104589c874d78429a25769802468a1097f910ca77c533ee388b40cac2ce48cb249173
6
+ metadata.gz: f765f7fca94f5590d5b4a123bb020d4ebf3b42d46d5f6e20343544faab6ae80df0dfcbcb17c0dc93a2ea0533391ec00a91b756d58d9fd05c3fecea63aca86a3a
7
+ data.tar.gz: d19a541703158bf3671ab61f6d44f1af364d23d44c907c96f4d2b14fd15c203af7f63df8b59129d63a2b3dd9d1af771f276f44ecf8924bfe50c942a8708a8165
data/README.markdown CHANGED
@@ -45,10 +45,10 @@ Inspired by [iulianu/iban-tools](https://github.com/iulianu/iban-tools). Please
45
45
 
46
46
  # This feature is intended to try to find all OCR numbers in a noisy bank statement string.
47
47
  # By design it may find too many numbers (e.g. valid substrings of other numbers), so you should check results against actual outstanding invoices.
48
- # By default, it excludes OCRs shorter than 4 digits, but this limit can be specified per below.
48
+ # By default, it excludes OCRs shorter than 4 digits and longer than 19 digits, but this limit can be specified per below.
49
49
  BankTools::SE::OCR.find_all_in_string("OCR1230 and ref4564 and 7890") # => [ "1230", "4564" ]
50
50
  BankTools::SE::OCR.find_all_in_string("1230 and 123067", length_digit: true, pad: "0") # => [ "123067" ]
51
- BankTools::SE::OCR.find_all_in_string("00 and 18", min_length: 2) # => [ "00", "18" ]
51
+ BankTools::SE::OCR.find_all_in_string("00 and 18 and 1230", min_length: 2, max_length: 3) # => [ "00", "18" ]
52
52
 
53
53
  # Plusgiro
54
54
 
@@ -64,13 +64,14 @@ module BankTools
64
64
  ocr[0...-digits_to_chop]
65
65
  end
66
66
 
67
- def self.find_all_in_string(string, length_digit: false, pad: "", min_length: 4)
67
+ # max_length is 19 because that's the longest allowed integer by default in a Postgres integer column with Ruby on Rails. So attempting some queries with longer OCRs may cause exceptions.
68
+ def self.find_all_in_string(string, length_digit: false, pad: "", min_length: 4, max_length: 19)
68
69
  expanded_string = string + " " + string.gsub("\n", "") + " " + string.gsub(";", "")
69
70
 
70
71
  numbers = expanded_string.scan(/\d+/)
71
72
 
72
73
  expanded_numbers = with_numbers_found_by_removing_prefix_and_postfix(numbers).
73
- reject { |n| n.length < min_length }
74
+ reject { |n| n.length < min_length || n.length > max_length }
74
75
 
75
76
  expanded_numbers.select { |candidate|
76
77
  begin
@@ -1,5 +1,5 @@
1
1
  module BankTools
2
2
  module SE
3
- VERSION = "2.3.0"
3
+ VERSION = "2.4.0"
4
4
  end
5
5
  end
data/spec/ocr_spec.rb CHANGED
@@ -120,6 +120,18 @@ describe BankTools::SE::OCR do
120
120
  expect(BankTools::SE::OCR.find_all_in_string("1234", min_length: 2)).to eq [ "34" ]
121
121
  end
122
122
 
123
+ it "lets you configure the accepted OCR max_length" do
124
+ ocr_length_19 = "1234567890123456785"
125
+ ocr_length_20 = "12345678901234567894"
126
+ string = "#{ocr_length_19} #{ocr_length_20}"
127
+
128
+ # Default max_length is 19.
129
+ expect(BankTools::SE::OCR.find_all_in_string(string)).to include ocr_length_19
130
+ expect(BankTools::SE::OCR.find_all_in_string(string)).not_to include ocr_length_20
131
+
132
+ expect(BankTools::SE::OCR.find_all_in_string(string, max_length: 20)).to include ocr_length_19, ocr_length_20
133
+ end
134
+
123
135
  it "excludes duplicates" do
124
136
  expect(BankTools::SE::OCR.find_all_in_string("1230 1230 4564")).to eq [ "1230", "4564" ]
125
137
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banktools-se
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh