Sha256: 833ec837e8cd552cbd6696bb92f417896150d252b28bf6bdb52c108b2abdbe70
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
require 'valvat' class Valvat module Checksum ALGORITHMS = {} def self.validate(vat) vat = Valvat(vat) algo = ALGORITHMS[vat.iso_country_code] Valvat::Syntax.validate(vat) && !!(algo.nil? || algo.new(vat).validate) end class Base def self.inherited(klass) ALGORITHMS[klass.name.split(/::/).last] = klass end attr_reader :vat def self.check_digit_length(len=nil) @check_digit_length = len if len @check_digit_length || 1 end def initialize(vat) @vat = vat end def validate check_digit == given_check_digit end private def given_check_digit_str str_wo_country[-self.class.check_digit_length..-1] end def given_check_digit given_check_digit_str.to_i end def figures_str str_wo_country[0..-(self.class.check_digit_length+1)] end def figures figures_str.split("").map(&:to_i) end def str_wo_country vat.to_s_wo_country end end end end Dir[File.dirname(__FILE__) + "/checksum/*.rb"].each do |file| require file end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
valvat-0.5.0 | lib/valvat/checksum.rb |