lib/banktools-se/ocr.rb in banktools-se-2.3.0 vs lib/banktools-se/ocr.rb in banktools-se-2.4.0
- old
+ new
@@ -62,16 +62,17 @@
digits_to_chop += strip_padding.length
ocr[0...-digits_to_chop]
end
- def self.find_all_in_string(string, length_digit: false, pad: "", min_length: 4)
+ # 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.
+ def self.find_all_in_string(string, length_digit: false, pad: "", min_length: 4, max_length: 19)
expanded_string = string + " " + string.gsub("\n", "") + " " + string.gsub(";", "")
numbers = expanded_string.scan(/\d+/)
expanded_numbers = with_numbers_found_by_removing_prefix_and_postfix(numbers).
- reject { |n| n.length < min_length }
+ reject { |n| n.length < min_length || n.length > max_length }
expanded_numbers.select { |candidate|
begin
to_number(candidate, length_digit: length_digit, pad: pad)
true