Class: Mail::Header
- Inherits:
-
Object
show all
- Defined in:
- lib/mail/header.rb
Instance Method Summary
collapse
Constructor Details
#initialize(options = nil) ⇒ Header
Returns a new instance of Header.
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/mail/header.rb', line 7
def initialize(options = nil)
@params = Hash.new
if options
if options.kind_of?(Hash) && options.key?(:content_type)
@params[:content_type] = ContentType.new(:type => options[:content_type])
elsif options.kind_of?(String)
set_params(options)
end
else
@params[:content_type] = ContentType.new
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/mail/header.rb', line 49
def method_missing(name, *args, &block)
if name.to_s.include?("=")
@params[name.to_s.delete("=").to_sym] = args.to_s
else
return @params[name]
end
end
|
Instance Method Details
#attachments? ⇒ Boolean
42
43
44
45
46
47
|
# File 'lib/mail/header.rb', line 42
def attachments?
if self.multipart?
return self.content_type.type.eql?("multipart/mixed")
end
return false
end
|
#multipart? ⇒ Boolean
38
39
40
|
# File 'lib/mail/header.rb', line 38
def multipart?
self.content_type.type.include?("multipart")
end
|
#to_json ⇒ Object
34
35
36
|
# File 'lib/mail/header.rb', line 34
def to_json
@params.to_json
end
|
#to_s ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/mail/header.rb', line 20
def to_s
= String.new
@params.each do |key, value|
case key
when :content_type
<< value.to_s
else
<< "#{format_key(key)}: #{value}\n"
end
end
<< @content_type.to_s
return
end
|