Class: ContentType
- Inherits:
-
Object
- Object
- ContentType
- Defined in:
- lib/content_type.rb,
lib/content_type/parser.rb,
lib/content_type/version.rb
Overview
ContentType structure
Defined Under Namespace
Classes: Parser
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #charset ⇒ Object
-
#initialize(parsed) ⇒ ContentType
constructor
A new instance of ContentType.
- #inspect ⇒ Object
- #mime_type ⇒ Object
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(parsed) ⇒ ContentType
Returns a new instance of ContentType.
12 13 14 15 16 17 18 |
# File 'lib/content_type.rb', line 12 def initialize(parsed) parsed = [parsed] unless parsed.is_a? Array @type = parsed.first[:type].to_s.downcase @subtype = parsed.first[:subtype].to_s.downcase @parameters = Hash[parse_parameters parsed[1..-1]] end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
10 11 12 |
# File 'lib/content_type.rb', line 10 def parameters @parameters end |
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
10 11 12 |
# File 'lib/content_type.rb', line 10 def subtype @subtype end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/content_type.rb', line 10 def type @type end |
Class Method Details
.parse(str) ⇒ Object
38 39 40 |
# File 'lib/content_type.rb', line 38 def self.parse(str) new Parser.new.parse str end |
Instance Method Details
#charset ⇒ Object
24 25 26 |
# File 'lib/content_type.rb', line 24 def charset parameters["charset"] end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/content_type.rb', line 28 def inspect "#<ContentType #{mime_type} #{parameters.inspect}>" end |
#mime_type ⇒ Object
20 21 22 |
# File 'lib/content_type.rb', line 20 def mime_type "#{type}/#{subtype}" end |
#to_s ⇒ Object Also known as: to_str
32 33 34 35 |
# File 'lib/content_type.rb', line 32 def to_s (["#{mime_type}"] + parameters.map { |k, v| "#{k}=#{v.to_s.inspect}" }) .compact.join("; ") end |