Sha256: 0a0e1e10acf9531058421dce1c6d4f004e50a8eac379135a19d462c9121da9f8

Contents?: true

Size: 712 Bytes

Versions: 6

Compression:

Stored size: 712 Bytes

Contents

require_relative 'base'
require_relative '../commons/mod11'

module BrDocuments
  module IE
    class Pattern2 < Base
      include Commons::Mod11

      def initialize(number)
        super
        @weight1 = [4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
        @weight2 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
      end

      protected

      def valid_format?
        regex = @mask
        regex.match(@number).present?
      end

      def valid_check_digit?
        @number.gsub!(/[\.\/-]/, '')

        digital_check1 = generate_check_digit(@number, @weight1)
        digital_check2 = generate_check_digit(@number, @weight2)

        @number[-2, 2] == "#{digital_check1}#{digital_check2}"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
br_documents-0.2.5 lib/br_documents/ie/pattern2.rb
br_documents-0.2.4 lib/br_documents/ie/pattern2.rb
br_documents-0.2.3 lib/br_documents/ie/pattern2.rb
br_documents-0.2.2 lib/br_documents/ie/pattern2.rb
br_documents-0.2.1 lib/br_documents/ie/pattern2.rb
br_documents-0.2.0 lib/br_documents/ie/pattern2.rb