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

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

Returns a new instance of IDNEmail.



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

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

Instance Attribute Details

#unicode_domainObject (readonly)

Returns the value of attribute unicode_domain.



26
27
28
# File 'lib/kdl/types/email.rb', line 26

def unicode_domain
  @unicode_domain
end

Class Method Details

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



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

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



41
42
43
# File 'lib/kdl/types/email.rb', line 41

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