lib/br_documents/ie/ap.rb in br_documents-0.2.3 vs lib/br_documents/ie/ap.rb in br_documents-0.2.4
- old
+ new
@@ -4,10 +4,14 @@
module BrDocuments
module IE
class AP < Base
include Commons::Mod11
+ def valid?
+ @number.to_s.size == 9 && super
+ end
+
protected
def format_ie(number)
number
end
@@ -16,9 +20,11 @@
regex = /(\d{9})$/
regex.match(@number).present?
end
def valid_check_digit?
+ return false if @number.to_i.zero?
+
weight = [9, 8, 7, 6, 5, 4, 3, 2]
detect_range_digits
@number[-1] == generate_check_digit(@number, weight).to_s
end