Class: KDL::Types::IDNHostname::Validator

Inherits:
Hostname::Validator show all
Defined in:
lib/kdl/types/hostname/validator.rb

Constant Summary

Constants inherited from Hostname::Validator

Hostname::Validator::PART_RGX

Instance Attribute Summary collapse

Attributes inherited from Hostname::Validator

#string

Instance Method Summary collapse

Methods inherited from Hostname::Validator

#valid?

Constructor Details

#initialize(string) ⇒ Validator

Returns a new instance of Validator.



38
39
40
41
42
43
44
45
46
47
# File 'lib/kdl/types/hostname/validator.rb', line 38

def initialize(string)
  is_ascii = string.split('.').any? { |x| x.start_with?('xn--') }
  if is_ascii
    super(string)
    @unicode = SimpleIDN.to_unicode(string)
  else
    super(SimpleIDN.to_ascii(string))
    @unicode = string
  end
end

Instance Attribute Details

#unicodeObject (readonly)

Returns the value of attribute unicode.



36
37
38
# File 'lib/kdl/types/hostname/validator.rb', line 36

def unicode
  @unicode
end