Class: MailXSMTPAPI::Field

Inherits:
Mail::UnstructuredField
  • Object
show all
Includes:
AsmGroupId, Category, Filters, Recipients, Sections, Substitutions, UniqueArguments
Defined in:
lib/mail_x_smtpapi/field.rb

Constant Summary collapse

FIELD_NAME =
'x-smtpapi'
CAPITALIZED_FIELD =
'X-SMTPAPI'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sections

#sections

Methods included from Filters

#filters

Methods included from AsmGroupId

#asm_group_id, #asm_group_id=

Methods included from Category

#category, #category=

Methods included from UniqueArguments

#unique_args, #unique_args=

Methods included from Substitutions

#merge_substitutions, #substitutions, #substitutions=

Methods included from Recipients

#to, #to=

Constructor Details

#initialize(value = nil, charset = 'utf-8') ⇒ Field

Returns a new instance of Field.



21
22
23
24
25
# File 'lib/mail_x_smtpapi/field.rb', line 21

def initialize(value = nil, charset = 'utf-8')
  self.charset = charset
  self.name = CAPITALIZED_FIELD
  @data = value || {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/mail_x_smtpapi/field.rb', line 10

def data
  @data
end

Instance Method Details

#decodedObject

to take advantage of folding, decoded must return a string of JSON with extra spaces inserted for line wrapping.



41
42
43
# File 'lib/mail_x_smtpapi/field.rb', line 41

def decoded
  value.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
end

#empty?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/mail_x_smtpapi/field.rb', line 45

def empty?
  data.values.all?{|v| !v || v.empty? }
end

#encodedObject



31
32
33
34
35
36
37
# File 'lib/mail_x_smtpapi/field.rb', line 31

def encoded
  if empty?
    ''
  else
    "#{wrapped_value}\r\n"
  end
end

#valueObject



27
28
29
# File 'lib/mail_x_smtpapi/field.rb', line 27

def value
  JSON.generate(data)
end