class VatId
Constants
- VERSION
Public Class Methods
new(code)
click to toggle source
# File lib/vat_id.rb, line 14 def initialize(code) @code = code.to_s.upcase.gsub(/[^A-Z0-9]/, '') end
specifications()
click to toggle source
# File lib/vat_id.rb, line 6 def self.specifications @@specs ||= YAML.load_file(File.expand_path('vat_id/specs.yml', File.dirname(__FILE__))) end
valid?(code)
click to toggle source
# File lib/vat_id.rb, line 10 def self.valid?(code) new(code).valid? end
Public Instance Methods
country_code()
click to toggle source
# File lib/vat_id.rb, line 18 def country_code @code[0..1] end
identifier()
click to toggle source
# File lib/vat_id.rb, line 22 def identifier @code[2..-1] end
to_s()
click to toggle source
# File lib/vat_id.rb, line 26 def to_s @code end
valid?()
click to toggle source
# File lib/vat_id.rb, line 30 def valid? !!specification && !!identifier.match(/^#{specification}$/) end
Private Instance Methods
specification()
click to toggle source
# File lib/vat_id.rb, line 36 def specification self.class.specifications[country_code.downcase] end