Class: Hermeneutics::ContentType

Inherits:
Contents show all
Defined in:
lib/hermeneutics/contents.rb

Constant Summary

Constants inherited from Dictionary

Dictionary::REA, Dictionary::RES, Dictionary::SEA, Dictionary::SEP, Dictionary::TSPECIAL

Instance Attribute Summary

Attributes inherited from Contents

#caption

Attributes inherited from Dictionary

#hash

Instance Method Summary collapse

Methods inherited from Contents

#=~, #encoded_parts, parse, #quoted_parts

Methods inherited from Dictionary

#[], #encode, #keys, #method_missing, parse, #to_s, urltext

Constructor Details

#initialize(line, sf = nil) ⇒ ContentType

:call-seq:

new( str)      -> cts

Create a ContentType object either out of a string from an E-Mail header field or from a value and a hash.

c = ContentType.parse "text/html; boundary=0123456"
c = ContentType.new "text/html", boundary: "0123456"


285
286
287
288
# File 'lib/hermeneutics/contents.rb', line 285

def initialize line, sf = nil
  line = line.join "/" if Array === line
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hermeneutics::Dictionary

Instance Method Details

#fulltypeObject

:call-seq:

fulltype      -> str

Find caption value of Content-Type style header field.

c = ContentType.new "text/html; boundary=0123456"
c.fulltype       #=>  "text/html"
c.type           #=>  "text"
c.subtype        #=>  "html"


312
# File 'lib/hermeneutics/contents.rb', line 312

def fulltype ; caption ; end

#parse_mime(input) ⇒ Object



328
329
330
331
# File 'lib/hermeneutics/contents.rb', line 328

def parse_mime input
  m = Mime.find @caption
  m and m.parse input, **@hash
end

#split_typeObject

:call-seq:

split_type      -> str

Find caption value of Content-Type style header field as an array

c = ContentType.new "text/html; boundary=0123456"
c.split_type       #=>  [ "text", "html"]
c.type           #=>  "text"
c.subtype        #=>  "html"


300
# File 'lib/hermeneutics/contents.rb', line 300

def split_type ; @split ||= (@caption.split "/", 2) ; end

#subtypeObject

:call-seq:

subtype      -> str

See fulltype or split_type.



326
# File 'lib/hermeneutics/contents.rb', line 326

def subtype ; split_type.last  ; end

#typeObject

:call-seq:

type      -> str

See fulltype or split_type.



319
# File 'lib/hermeneutics/contents.rb', line 319

def type    ; split_type.first ; end