Class: Mbox::Mail::Headers::ContentType
- Inherits:
-
Object
- Object
- Mbox::Mail::Headers::ContentType
- Defined in:
- lib/mbox/mail/headers/content_type.rb
Instance Attribute Summary collapse
-
#boundary ⇒ Object
Returns the value of attribute boundary.
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#mime ⇒ Object
Returns the value of attribute mime.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ ContentType
constructor
A new instance of ContentType.
- #to_s ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ ContentType
Returns a new instance of ContentType.
45 46 47 48 49 |
# File 'lib/mbox/mail/headers/content_type.rb', line 45 def initialize (data = {}) @mime = data[:mime] || 'text/plain' @charset = data[:charset] @boundary = data[:boundary] end |
Instance Attribute Details
#boundary ⇒ Object
Returns the value of attribute boundary.
43 44 45 |
# File 'lib/mbox/mail/headers/content_type.rb', line 43 def boundary @boundary end |
#charset ⇒ Object
Returns the value of attribute charset.
43 44 45 |
# File 'lib/mbox/mail/headers/content_type.rb', line 43 def charset @charset end |
#mime ⇒ Object
Returns the value of attribute mime.
43 44 45 |
# File 'lib/mbox/mail/headers/content_type.rb', line 43 def mime @mime end |
Class Method Details
.parse(text) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mbox/mail/headers/content_type.rb', line 23 def self.parse (text) return text if text.is_a?(ContentType) return ContentType.new unless text && text.is_a?(String) stuff = text.gsub(/\n\r/, '').split(/\s*;\s*/) type = stuff.shift ContentType.new(Hash[stuff.map {|stuff| stuff = stuff.strip.split(/=/) stuff[0] = stuff[0].to_sym if stuff[1][0] == '"' && stuff[1][stuff[1].length-1] == '"' stuff[1] = stuff[1][1, stuff[1].length-2] end stuff }].merge(mime: type)) end |
Instance Method Details
#to_s ⇒ Object
51 52 53 |
# File 'lib/mbox/mail/headers/content_type.rb', line 51 def to_s "#{mime}#{"; charset=#{charset}" if charset}#{"; boundary=#{boundary}" if boundary}" end |