Class: Hermeneutics::Contents
- Inherits:
-
Dictionary
- Object
- Dictionary
- Hermeneutics::Contents
- Defined in:
- lib/hermeneutics/contents.rb
Overview
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. #=> "text/html"
content_type[ :boundary] #=> "0123456"
# (Subclass ContentType even splits the caption into type/subtype.)
Direct Known Subclasses
Constant Summary
Constants inherited from Dictionary
Dictionary::REA, Dictionary::RES, Dictionary::SEA, Dictionary::SEP, Dictionary::TSPECIAL
Instance Attribute Summary collapse
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
Attributes inherited from Dictionary
Class Method Summary collapse
-
.parse(line) ⇒ Object
Create a
Contents
object out of a string from a mail header field.
Instance Method Summary collapse
- #=~(re) ⇒ Object
- #encoded_parts ⇒ Object
-
#initialize(caption, hash = nil) ⇒ Contents
constructor
Create a
Contents
object from a value and a hash. - #quoted_parts ⇒ Object
Methods inherited from Dictionary
#[], #encode, #keys, #method_missing, #to_s, urltext
Constructor Details
#initialize(caption, hash = nil) ⇒ Contents
Create a Contents
object from a value and a hash.
c = Contents.new "text/html", boundary: "0123456"
247 248 249 250 251 252 253 |
# File 'lib/hermeneutics/contents.rb', line 247 def initialize , hash = nil if =~ RES or =~ REA then raise "Invalid content caption '#{}'." end @caption = .new_string super hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hermeneutics::Dictionary
Instance Attribute Details
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
241 242 243 |
# File 'lib/hermeneutics/contents.rb', line 241 def @caption end |
Class Method Details
.parse(line) ⇒ Object
Create a Contents
object out of a string from a mail header field.
c = Contents.parse "text/html; boundary=0123456"
c. #=> "text/html"
c[ :boundary] #=> "0123456"
232 233 234 235 236 237 |
# File 'lib/hermeneutics/contents.rb', line 232 def parse line rest = line.strip , rest = rest.split Dictionary::RES, 2 hash = parse_hash rest new , hash end |
Instance Method Details
#=~(re) ⇒ Object
255 256 257 |
# File 'lib/hermeneutics/contents.rb', line 255 def =~ re @caption =~ re end |
#encoded_parts ⇒ Object
266 267 268 269 270 |
# File 'lib/hermeneutics/contents.rb', line 266 def encoded_parts r = [ "#@caption"] r.concat super r end |
#quoted_parts ⇒ Object
260 261 262 263 264 |
# File 'lib/hermeneutics/contents.rb', line 260 def quoted_parts r = [ "#@caption"] r.concat super r end |