Sha256: 23a2ee33c1311c231e863e96741c34b57db95e6b0765e09ad4b9f822ab4ffed5

Contents?: true

Size: 740 Bytes

Versions: 23

Compression:

Stored size: 740 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 = /[-\.:_\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.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

23 entries across 23 versions & 2 rubygems

Version Path
valvat-0.8.1 lib/valvat/utils.rb
valvat-0.8.0 lib/valvat/utils.rb
valvat-0.7.4 lib/valvat/utils.rb
valvat-0.7.3 lib/valvat/utils.rb
valvat-0.7.2 lib/valvat/utils.rb
valvat-0.7.1 lib/valvat/utils.rb
valvat-0.7.0 lib/valvat/utils.rb
valvat-0.6.11 lib/valvat/utils.rb
valvat-0.6.10 lib/valvat/utils.rb
valvat-0.6.9 lib/valvat/utils.rb
valvat-0.6.8 lib/valvat/utils.rb
valvat-core-0.0.1 lib/valvat/utils.rb
valvat-0.6.7 lib/valvat/utils.rb
valvat-0.6.6 lib/valvat/utils.rb
valvat-0.6.5 lib/valvat/utils.rb
valvat-0.6.4 lib/valvat/utils.rb
valvat-0.6.3 lib/valvat/utils.rb
valvat-0.6.2 lib/valvat/utils.rb
valvat-0.6.1 lib/valvat/utils.rb
valvat-0.6.0 lib/valvat/utils.rb