Class: KDL::Types::Hostname::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/kdl/types/hostname/validator.rb

Direct Known Subclasses

IDNHostname::Validator

Constant Summary collapse

PART_RGX =
/^[a-z0-9_][a-z0-9_\-]{0,62}$/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Validator

Returns a new instance of Validator.



13
14
15
# File 'lib/kdl/types/hostname/validator.rb', line 13

def initialize(string)
  @string = string
end

Instance Attribute Details

#stringObject (readonly) Also known as: ascii, unicode

Returns the value of attribute string.



9
10
11
# File 'lib/kdl/types/hostname/validator.rb', line 9

def string
  @string
end

Instance Method Details

#valid?Boolean

Returns:



17
18
19
20
21
# File 'lib/kdl/types/hostname/validator.rb', line 17

def valid?
  return false if @string.length > 253

  @string.split('.').all? { |x| valid_part?(x) }
end