Sha256: 42b1c197ac27f31219ed0cc6e59b095db9bf87895a13cd42a27432d06f7d9740

Contents?: true

Size: 607 Bytes

Versions: 1

Compression:

Stored size: 607 Bytes

Contents

require 'valvat/checksum'

class Valvat
  module Checksum
    class IE < Base
      def check_digit
        figures.reverse.each_with_index.map do |fig, i|
          fig*(i+2)
        end.inject(:+).modulo(23)
      end

      CHARS = "WABCDEFGHIJKLMNOPQRSTUV".split("")

      def given_check_digit
        CHARS.index(given_check_digit_str)
      end

      def str_wo_country
        str = super
        # Convert old irish vat format to new one
        if str =~ /\A[0-9][A-Z][0-9]{5}[A-Z]\Z/
          "0#{str[2..6]}#{str[0]}#{str[7]}"
        else
          str
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
valvat-0.5.0 lib/valvat/checksum/ie.rb