Sha256: 1a46197585e307f0e52100b88de3f8200da791bf6c3ed61e6f7d40243b6e5678

Contents?: true

Size: 596 Bytes

Versions: 3

Compression:

Stored size: 596 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/
    
    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(/\A\s+|\s+\Z/, "")
    end
    
    def self.vat_country_to_iso_country(vat_country)
      vat_country == "EL" ? "GR" : vat_country
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
valvat-0.2.2 lib/valvat/utils.rb
valvat-0.2.1 lib/valvat/utils.rb
valvat-0.2.0 lib/valvat/utils.rb