Sha256: ab86d1651b2e89a396b6d56781966523eb66d2ae6efb73329ba733ed991efef4
Contents?: true
Size: 905 Bytes
Versions: 5
Compression:
Stored size: 905 Bytes
Contents
class Valvat module Checksum class IE < Base def check_digit total = sum_figures_by do |fig, i| fig*(i+2) end if str_wo_country.size == 9 total += (CHARS.index(str_wo_country[8]) * 9) end total.modulo(23) end CHARS = "WABCDEFGHIJKLMNOPQRSTUV".split("") 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 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 def figures_str if super.size == 8 super[0...-1] else super end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems