Class: KDL::Types::IDNEmail

Inherits:
Email show all
Defined in:
lib/kdl/types/email.rb

Constant Summary

Constants inherited from Value

Value::Null

Instance Attribute Summary collapse

Attributes inherited from Email

#domain, #local

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_domain:, **kwargs) ⇒ IDNEmail

Returns a new instance of IDNEmail.



30
31
32
33
# File 'lib/kdl/types/email.rb', line 30

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

Dynamic Method Handling

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

Instance Attribute Details

#unicode_domainObject (readonly)

Returns the value of attribute unicode_domain.



28
29
30
# File 'lib/kdl/types/email.rb', line 28

def unicode_domain
  @unicode_domain
end

Class Method Details

.call(value, type = 'email') ⇒ Object



35
36
37
38
39
40
41
# File 'lib/kdl/types/email.rb', line 35

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

  local, domain, unicode_domain = Email::Parser.new(value.value, idn: true).parse

  new("#{local}@#{domain}", type: type, local: local, domain: domain, unicode_domain: unicode_domain)
end

Instance Method Details

#unicode_valueObject



43
44
45
# File 'lib/kdl/types/email.rb', line 43

def unicode_value
  "#{local}@#{unicode_domain}"
end