class Valvat::Checksum::IE

Constants

CHARS

Public Instance Methods

check_digit() click to toggle source
# File lib/valvat/checksum/ie.rb, line 6
def check_digit
  total = sum_figures_by do |fig, i|
    fig * (i + 2)
  end
  total += ((CHARS.index(str_wo_country[8]) || 0) * 9) if str_wo_country.size == 9
  total.modulo(23)
end
figures_str() click to toggle source
Calls superclass method Valvat::Checksum::Base#figures_str
# File lib/valvat/checksum/ie.rb, line 34
def figures_str
  if super.size == 8
    super[0...-1]
  else
    super
  end
end
given_check_digit() click to toggle source
# File lib/valvat/checksum/ie.rb, line 16
def given_check_digit
  if str_wo_country.size == 9
    CHARS.index(str_wo_country[7])
  else
    CHARS.index(given_check_digit_str)
  end
end
str_wo_country() click to toggle source
Calls superclass method Valvat::Checksum::Base#str_wo_country
# File lib/valvat/checksum/ie.rb, line 24
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