Class: KDL::Types::IDNHostname

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

Defined Under Namespace

Classes: Validator

Constant Summary

Constants inherited from Value

Value::Null

Instance Attribute Summary collapse

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#as_type, from, #stringify_value, #to_s

Constructor Details

#initialize(value, unicode_value:, **kwargs) ⇒ IDNHostname

Returns a new instance of IDNHostname.



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

def initialize(value, unicode_value:, **kwargs)
  super(value, **kwargs)
  @unicode_value = unicode_value
end

Instance Attribute Details

#unicode_valueObject (readonly)

Returns the value of attribute unicode_value.



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

def unicode_value
  @unicode_value
end

Class Method Details

.call(value, type = 'idn-hostname') ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
# File 'lib/kdl/types/hostname.rb', line 25

def self.call(value, type = 'idn-hostname')
  return nil unless value.is_a? ::KDL::Value::String

  validator = Validator.new(value.value)
  raise ArgumentError, "invalid hostname #{value}" unless validator.valid?

  new(validator.ascii, type: type, unicode_value: validator.unicode)
end