Class: UpiLink::VpaValidator

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

Constant Summary collapse

VPA_REGEX =
/\A[\w.\-]{2,256}@[a-zA-Z][a-zA-Z0-9]{1,64}\z/

Class Method Summary collapse

Class Method Details

.valid?(vpa) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/upi_link/vpa_validator.rb', line 5

def self.valid?(vpa)
  return false if vpa.nil? || vpa.strip.empty?
  !!(vpa.match?(VPA_REGEX))
end

.validate!(vpa) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/upi_link/vpa_validator.rb', line 10

def self.validate!(vpa)
  raise ArgumentError, "Invalid VPA format: #{vpa.inspect}" unless valid?(vpa)
  true
end