Sha256: 0165d23932998d22b616c80411ff7fec8a9f1d24cc796e4bdb7074bd4d54eba4

Contents?: true

Size: 708 Bytes

Versions: 6

Compression:

Stored size: 708 Bytes

Contents

require_relative 'pattern1'

module BrDocuments
  module IE
    class TO < Pattern1
      def initialize(number)
        super
        if number.gsub(/(\.)|(\-)/, '').length == 9
          @mask = /^(\d{2}\.\d{6}\-\d{1})$|^(\d{9})$/
          @weight = [9, 8, 7, 6, 5, 4, 3, 2]
        else
          @mask = /^(\d{2}\.\d{2}\.\d{6}\-\d{1})$|^(\d{11})$/
          @weight = [9, 8, 0, 0, 7, 6, 5, 4, 3, 2]
        end
      end

      private

      def format_ie(number)
        if number.gsub(/(\.)|(\-)/, '').length == 9
          number.sub(/(\d{2})(\d{6})(\d{1})/, '\\1.\\2-\\3')
        else
          number.sub(/(\d{2})(\d{2})(\d{6})(\d{1})/, '\\1.\\2.\\3-\\4')
        end
      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/to.rb
br_documents-0.2.4 lib/br_documents/ie/to.rb
br_documents-0.2.3 lib/br_documents/ie/to.rb
br_documents-0.2.2 lib/br_documents/ie/to.rb
br_documents-0.2.1 lib/br_documents/ie/to.rb
br_documents-0.2.0 lib/br_documents/ie/to.rb