Class: Mail::ContentTypeField
Constant Summary
collapse
- FIELD_NAME =
'content-type'
- CAPITALIZED_FIELD =
'Content-Type'
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utilities
included
included
Constructor Details
Returns a new instance of ContentTypeField.
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/mail/fields/content_type_field.rb', line 11
def initialize(*args)
if args.last.class == Array
@main_type = args.last[0]
@sub_type = args.last[1]
@parameters = ParameterHash.new.merge!(args.last.last)
super(CAPITALIZED_FIELD, args.last)
else
@main_type = nil
@sub_type = nil
@parameters = nil
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, args.last))
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/mail/fields/content_type_field.rb', line 105
def method_missing(name, *args, &block)
if name.to_s =~ /([\w_]+)=/
self.parameters[$1] = args.first
@value = "#{content_type}; #{stringify(parameters)}"
else
super
end
end
|
Class Method Details
.generate_boundary ⇒ Object
66
67
68
|
# File 'lib/mail/fields/content_type_field.rb', line 66
def ContentTypeField.generate_boundary
"--==_mimepart_#{Mail.random_tag}"
end
|
.with_boundary(type) ⇒ Object
62
63
64
|
# File 'lib/mail/fields/content_type_field.rb', line 62
def ContentTypeField.with_boundary(type)
new("#{type}; boundary=#{generate_boundary}")
end
|
Instance Method Details
#decoded ⇒ Object
99
100
101
|
# File 'lib/mail/fields/content_type_field.rb', line 99
def decoded
value
end
|
#default ⇒ Object
48
49
50
|
# File 'lib/mail/fields/content_type_field.rb', line 48
def default
decoded
end
|
#element ⇒ Object
30
31
32
33
34
|
# File 'lib/mail/fields/content_type_field.rb', line 30
def element
@element ||= Mail::ContentTypeElement.new(value)
rescue
@element ||= Mail::ContentTypeElement.new(sanatize(value))
end
|
#encoded ⇒ Object
95
96
97
|
# File 'lib/mail/fields/content_type_field.rb', line 95
def encoded
"#{CAPITALIZED_FIELD}: #{content_type};\r\n\t#{parameters.encoded};\r\n"
end
|
#filename ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/mail/fields/content_type_field.rb', line 82
def filename
case
when parameters['filename']
@filename = parameters['filename']
when parameters['name']
@filename = parameters['name']
else
@filename = nil
end
@filename
end
|
#main_type ⇒ Object
36
37
38
|
# File 'lib/mail/fields/content_type_field.rb', line 36
def main_type
@main_type ||= element.main_type
end
|
#parameters ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/mail/fields/content_type_field.rb', line 54
def parameters
unless @parameters
@parameters = ParameterHash.new
element.parameters.each { |p| @parameters.merge!(p) }
end
@parameters
end
|
#string ⇒ Object
Also known as:
content_type
44
45
46
|
# File 'lib/mail/fields/content_type_field.rb', line 44
def string
"#{main_type}/#{sub_type}"
end
|
#stringify(params) ⇒ Object
78
79
80
|
# File 'lib/mail/fields/content_type_field.rb', line 78
def stringify(params)
params.map { |k,v| "#{k}=#{Encodings.param_encode(v)}" }.join("; ")
end
|
#sub_type ⇒ Object
40
41
42
|
# File 'lib/mail/fields/content_type_field.rb', line 40
def sub_type
@sub_type ||= element.sub_type
end
|
#tree ⇒ Object
25
26
27
28
|
# File 'lib/mail/fields/content_type_field.rb', line 25
def tree
@element ||= Mail::ContentTypeElement.new(value)
@tree ||= @element.tree
end
|
#value ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/mail/fields/content_type_field.rb', line 70
def value
if @value.class == Array
"#{@main_type}/#{@sub_type}; #{stringify(parameters)}"
else
@value
end
end
|