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.



15
16
17
# File 'lib/kdl/types/hostname/validator.rb', line 15

def initialize(string)
  @string = string
end

Instance Attribute Details

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

Returns the value of attribute string.



11
12
13
# File 'lib/kdl/types/hostname/validator.rb', line 11

def string
  @string
end

Instance Method Details

#valid?Boolean

Returns:



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

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

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