Class: VatValidator::VatNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/vat_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(number, country_code = nil) ⇒ VatNumber

Returns a new instance of VatNumber.



66
67
68
69
# File 'lib/vat_validator.rb', line 66

def initialize(number, country_code = nil)
  @number = number
  @country_code = country_code
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
# File 'lib/vat_validator.rb', line 71

def valid?
  if @country_code
    VAT_PATTERNS.has_key?(@country_code) && @number.to_s =~ VAT_PATTERNS[@country_code]
  else
    VAT_PATTERNS.values.detect { |p| @number.to_s =~ p }
  end
end