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.2"
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.
10 11 12 13 14 15 16 |
# File 'lib/content_type.rb', line 10 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 = (parse_parameters parsed[1..-1]).to_h end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
8 9 10 |
# File 'lib/content_type.rb', line 8 def parameters @parameters end |
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
8 9 10 |
# File 'lib/content_type.rb', line 8 def subtype @subtype end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/content_type.rb', line 8 def type @type end |
Class Method Details
.parse(str) ⇒ Object
36 37 38 |
# File 'lib/content_type.rb', line 36 def self.parse(str) new Parser.new.parse str end |
Instance Method Details
#charset ⇒ Object
22 23 24 |
# File 'lib/content_type.rb', line 22 def charset parameters["charset"] end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/content_type.rb', line 26 def inspect "#<ContentType #{mime_type} #{parameters.inspect}>" end |
#mime_type ⇒ Object
18 19 20 |
# File 'lib/content_type.rb', line 18 def mime_type "#{type}/#{subtype}" end |
#to_s ⇒ Object Also known as: to_str
30 31 32 33 |
# File 'lib/content_type.rb', line 30 def to_s ([mime_type.to_s] + parameters.map { |k, v| "#{k}=#{v.to_s.inspect}" }) .compact.join("; ") end |