Module: Aquatone::Validation

Defined in:
lib/aquatone/validation.rb

Constant Summary collapse

DOMAIN_REGEX =
/\A([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\z/.freeze
MIN_PORT =
1.freeze
MAX_PORT =
65535.freeze

Class Method Summary collapse

Class Method Details

.valid_domain_name?(value) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/aquatone/validation.rb', line 7

def self.valid_domain_name?(value)
  value.to_s =~ DOMAIN_REGEX ? true : false
end

.valid_ip?(value) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/aquatone/validation.rb', line 11

def self.valid_ip?(value)
  IPAddr.new(value)
  true
rescue IPAddr::Error
  false
end

.valid_tcp_port?(value) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/aquatone/validation.rb', line 18

def self.valid_tcp_port?(value)
  value.to_i.between?(MIN_PORT, MAX_PORT)
end