Class: MailXSMTPAPI::Field
- Inherits:
-
Mail::UnstructuredField
- Object
- Mail::UnstructuredField
- MailXSMTPAPI::Field
- 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
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#decoded ⇒ Object
to take advantage of folding, decoded must return a string of JSON with extra spaces inserted for line wrapping.
- #empty? ⇒ Boolean
- #encoded ⇒ Object
-
#initialize(value = nil, charset = 'utf-8') ⇒ Field
constructor
A new instance of Field.
- #value ⇒ Object
Methods included from Sections
Methods included from Filters
Methods included from AsmGroupId
Methods included from Category
Methods included from UniqueArguments
Methods included from Substitutions
#merge_substitutions, #substitutions, #substitutions=
Methods included from Recipients
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
#data ⇒ Object (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
#decoded ⇒ Object
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
45 46 47 |
# File 'lib/mail_x_smtpapi/field.rb', line 45 def empty? data.values.all?{|v| !v || v.empty? } end |
#encoded ⇒ Object
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 |
#value ⇒ Object
27 28 29 |
# File 'lib/mail_x_smtpapi/field.rb', line 27 def value JSON.generate(data) end |