Sha256: 0e7a3c240fe521fe5a1adfc6d95f3371f6ce8f7745b74404a73ce423fc2c43ec

Contents?: true

Size: 639 Bytes

Versions: 4

Compression:

Stored size: 639 Bytes

Contents

class Valvat
  module Utils
    
    EU_COUNTRIES = %w(AT BE BG CY CZ DE DK EE ES FI FR GB GR HU IE IT LT LU LV MT NL PL PT RO SE SI SK)
    COUNTRY_PATTERN = /\A([A-Z]{2})(.+)\Z/
    NORMALIZE_PATTERN = /[-\.:_\s,;]+/
    
    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.upcase.gsub(NORMALIZE_PATTERN, "")
    end
    
    def self.vat_country_to_iso_country(vat_country)
      vat_country == "EL" ? "GR" : vat_country
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
valvat-0.3.2 lib/valvat/utils.rb
valvat-0.3.1 lib/valvat/utils.rb
valvat-0.3.0 lib/valvat/utils.rb
valvat-0.2.3 lib/valvat/utils.rb