Class: VatValidator::VatNumber
- Inherits:
-
Object
- Object
- VatValidator::VatNumber
- Defined in:
- lib/vat_validator.rb
Instance Method Summary collapse
-
#initialize(number, country_code = nil) ⇒ VatNumber
constructor
A new instance of VatNumber.
- #valid? ⇒ Boolean
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
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 |