lib/br_documents/ie/ap.rb in br_documents-0.2.4 vs lib/br_documents/ie/ap.rb in br_documents-0.2.5
- old
+ new
@@ -20,22 +20,22 @@
regex = /(\d{9})$/
regex.match(@number).present?
end
def valid_check_digit?
- return false if @number.to_i.zero?
+ return false if number_to_calculate_digits < 3_000_001
weight = [9, 8, 7, 6, 5, 4, 3, 2]
detect_range_digits
@number[-1] == generate_check_digit(@number, weight).to_s
end
private
# rubocop:disable Metrics/MethodLength
def detect_range_digits
- number = @number[0, 8].to_i
+ number = number_to_calculate_digits
if number >= 3_000_001 && number <= 3_017_000
@p = 5
@d = 0
elsif number >= 3_017_001 && number <= 3_019_022
@@ -45,9 +45,13 @@
@p = 0
@d = 0
end
end
# rubocop:enable Metrics/MethodLength
+
+ def number_to_calculate_digits
+ @number[0, 8].to_i
+ end
def generate_check_digit(values, weights)
sum = reduce_weights(values, weights)
sum += @p
mod = sum % 11