lib/valvat/syntax.rb in valvat-0.0.3 vs lib/valvat/syntax.rb in valvat-0.1.0
- old
+ new
@@ -1,10 +1,8 @@
require 'valvat/utils'
module Valvat
- class InvalidSyntax < StandardError;end
-
module Syntax
VAT_PATTERNS = {
'AT' => /\AATU[0-9]{8}\Z/, # Austria
'BE' => /\ABE[0-9]{10}\Z/, # Belgium
@@ -12,11 +10,11 @@
'CY' => /\ACY[0-9]{8}[A-Z]\Z/, # Cyprus
'CZ' => /\ACZ[0-9]{8,10}\Z/, # Czech Republic
'DE' => /\ADE[0-9]{9}\Z/, # Germany
'DK' => /\ADK[0-9]{8}\Z/, # Denmark
'EE' => /\AEE[0-9]{9}\Z/, # Estonia
- 'EL' => /\AEL[0-9]{9}\Z/, # Greece
+ 'GR' => /\AEL[0-9]{9}\Z/, # Greece
'ES' => /\AES([A-Z][0-9]{8}|[0-9]{8}[A-Z]|[A-Z][0-9]{7}[A-Z])\Z/, # Spain
'FI' => /\AFI[0-9]{8}\Z/, # Finland
'FR' => /\AFR[A-Z0-9]{2}[0-9]{9}\Z/, # France
'GB' => /\AGB([0-9]{9}|[0-9]{12}|(HA|GD)[0-9]{3})\Z/, # United Kingdom
'HU' => /\AHU[0-9]{8}\Z/, # Hungary
@@ -36,13 +34,9 @@
}
def self.validate(vat)
pattern = VAT_PATTERNS[Valvat::Utils.split(vat)[0]]
!!(pattern && pattern =~ vat)
- end
-
- def self.validate!(vat)
- validate(vat) || raise(Valvat::InvalidSyntax.new("#{vat.inspect} is an invalid vat number!"))
end
end
end
\ No newline at end of file