Module: EuVat

Defined in:
lib/eu_vat.rb,
lib/eu_vat/version.rb

Overview

Encapsulates the library implementation.

Constant Summary collapse

NORMALIZE_RE =
/[^\d^[A-Z]]/
VALIDATE_RE =
/\A([A-Z]{2})([\d[A-Z]]+)\Z/
VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.format(normalized_number) ⇒ Object



14
15
16
17
18
19
# File 'lib/eu_vat.rb', line 14

def self.format(normalized_number)
  [
    normalized_number[0, 2],
    normalized_number[2..]
  ].join('.')
end

.normalize(formatted_number) ⇒ Object



10
11
12
# File 'lib/eu_vat.rb', line 10

def self.normalize(formatted_number)
  formatted_number.upcase.gsub(NORMALIZE_RE, '')
end

.validate(normalized_number) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/eu_vat.rb', line 21

def self.validate(normalized_number)
  match = VALIDATE_RE.match(normalized_number)
  if match
    []
  else
    [{ error: :invalid }]
  end
end