Sha256: dd93a1c66f905968b04725ab8964162e84df1130d83f91449c107a9e00ca920c
Contents?: true
Size: 758 Bytes
Versions: 4
Compression:
Stored size: 758 Bytes
Contents
class Valvat module Utils EU_COUNTRIES = %w(AT BE BG CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU LV MT NL PL PT RO SE SI SK) COUNTRY_PATTERN = /\A([A-Z]{2})(.+)\Z/ NORMALIZE_PATTERN = /[[:space:][:punct:][:cntrl:]]+/ def self.split(vat) COUNTRY_PATTERN =~ vat result = [$1, $2] iso_country = vat_country_to_iso_country(result[0]) EU_COUNTRIES.include?(iso_country) ? result : [nil, nil] end def self.normalize(vat) vat.to_s.upcase.gsub(NORMALIZE_PATTERN, "") end def self.vat_country_to_iso_country(vat_country) vat_country == "EL" ? "GR" : vat_country end def self.iso_country_to_vat_country(iso_country) iso_country == "GR" ? "EL" : iso_country end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
valvat-1.0.0 | lib/valvat/utils.rb |
valvat-0.9.1 | lib/valvat/utils.rb |
valvat-0.9.0 | lib/valvat/utils.rb |
valvat-0.8.2 | lib/valvat/utils.rb |