class Hermes::Contents
A parser for header fields in Content-Type style
Example¶ ↑
content_disposition = Contents.new "form-data", :name => "mycontrol" content_type = Contents.parse "text/html; boundary=0123456" content_type.caption #=> "text/html" content_type[ :boundary] #=> "0123456" # (Subclass ContentType even splits the caption into type/subtype.)
Attributes
Public Class Methods
new(caption, hash = nil)
click to toggle source
Create a Contents
object from a value and a hash.
c = Contents.new "text/html", :boundary => "0123456"
Calls superclass method
Hermes::Dictionary.new
# File lib/hermes/contents.rb, line 246 def initialize caption, hash = nil if caption =~ RES or caption =~ REA then raise "Invalid content caption '#{caption}'." end @caption = caption.new_string super hash end
Public Instance Methods
=~(re)
click to toggle source
# File lib/hermes/contents.rb, line 254 def =~ re @caption =~ re end
encoded_parts()
click to toggle source
Calls superclass method
Hermes::Dictionary#encoded_parts
# File lib/hermes/contents.rb, line 265 def encoded_parts r = [ "#@caption"] r.concat super r end
parse(line)
click to toggle source
Create a Contents
object out of a string from a mail header
field.
c = Contents.parse "text/html; boundary=0123456" c.caption #=> "text/html" c[ :boundary] #=> "0123456"
# File lib/hermes/contents.rb, line 231 def parse line rest = line.strip caption, rest = rest.split Dictionary::RES, 2 hash = parse_hash rest new caption, hash end
quoted_parts()
click to toggle source
Calls superclass method
Hermes::Dictionary#quoted_parts
# File lib/hermes/contents.rb, line 259 def quoted_parts r = [ "#@caption"] r.concat super r end