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.caption #=> "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
-
.build_args(rest) ⇒ Object
Create a
Contentsobject out of a string from a mail header field.
Instance Method Summary collapse
- #=~(re) ⇒ Object
- #empty? ⇒ Boolean
- #encoded_parts ⇒ Object
-
#initialize(caption, hash = nil) ⇒ Contents
constructor
Create a
Contentsobject from a value and a hash. - #notempty? ⇒ Boolean
- #quoted_parts ⇒ Object
Methods inherited from Dictionary
#[], #encode, #keys, parse, #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"
253 254 255 256 257 258 259 |
# File 'lib/hermeneutics/contents.rb', line 253 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 |
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.
247 248 249 |
# File 'lib/hermeneutics/contents.rb', line 247 def caption @caption end |
Class Method Details
.build_args(rest) ⇒ Object
240 241 242 243 |
# File 'lib/hermeneutics/contents.rb', line 240 def build_args rest caption, rest = rest.split Dictionary::RES, 2 [ caption, *(super rest)] end |
Instance Method Details
#=~(re) ⇒ Object
264 265 266 |
# File 'lib/hermeneutics/contents.rb', line 264 def =~ re @caption =~ re end |
#empty? ⇒ Boolean
261 |
# File 'lib/hermeneutics/contents.rb', line 261 def empty? ; @caption.empty? and super ; end |
#encoded_parts ⇒ Object
275 276 277 278 279 |
# File 'lib/hermeneutics/contents.rb', line 275 def encoded_parts r = [ "#@caption"] r.concat super r end |
#notempty? ⇒ Boolean
262 |
# File 'lib/hermeneutics/contents.rb', line 262 def notempty? ; self if @caption.notempty? or super ; end |
#quoted_parts ⇒ Object
269 270 271 272 273 |
# File 'lib/hermeneutics/contents.rb', line 269 def quoted_parts r = [ "#@caption"] r.concat super r end |