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::Custom

#oriinal_value

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value::Custom

#to_v1, #to_v2, #version

Methods inherited from Value

#==, #as_type, from, #inspect, #method_missing, #respond_to_missing?, #stringify_value, #to_s, #to_v2, #version

Constructor Details

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

Returns a new instance of IDNHostname.



22
23
24
25
# File 'lib/kdl/types/hostname.rb', line 22

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class KDL::Value

Instance Attribute Details

#unicode_valueObject (readonly)

Returns the value of attribute unicode_value.



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

def unicode_value
  @unicode_value
end

Class Method Details

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

Raises:

  • (ArgumentError)


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

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