Class: Protocol::HTTP::Header::Accept::MediaRange
- Inherits:
-
Struct
- Object
- Struct
- Protocol::HTTP::Header::Accept::MediaRange
- Defined in:
- lib/protocol/http/header/accept.rb
Overview
A single entry in the Accept: header, which includes a mime type and associated parameters. A media range can include wild cards, but a media type is a specific type and subtype.
Instance Attribute Summary collapse
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#subtype ⇒ Object
Returns the value of attribute subtype.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare the media range with another media range or a string, based on the quality factor.
-
#initialize(type, subtype = "*", parameters = {}) ⇒ MediaRange
constructor
Create a new media range.
-
#quality_factor ⇒ Object
The quality factor associated with the media range, which is used to determine the order of preference.
-
#to_s ⇒ Object
(also: #to_str)
The string representation of the media range, including the type, subtype, and any parameters.
Constructor Details
#initialize(type, subtype = "*", parameters = {}) ⇒ MediaRange
Create a new media range.
39 40 41 |
# File 'lib/protocol/http/header/accept.rb', line 39 def initialize(type, subtype = "*", parameters = {}) super(type, subtype, parameters) end |
Instance Attribute Details
#parameters ⇒ Object
Returns the value of attribute parameters
33 34 35 |
# File 'lib/protocol/http/header/accept.rb', line 33 def parameters @parameters end |
#subtype ⇒ Object
Returns the value of attribute subtype
33 34 35 |
# File 'lib/protocol/http/header/accept.rb', line 33 def subtype @subtype end |
#type ⇒ Object
Returns the value of attribute type
33 34 35 |
# File 'lib/protocol/http/header/accept.rb', line 33 def type @type end |
Instance Method Details
#<=>(other) ⇒ Object
Compare the media range with another media range or a string, based on the quality factor.
44 45 46 |
# File 'lib/protocol/http/header/accept.rb', line 44 def <=> other other.quality_factor <=> self.quality_factor end |
#quality_factor ⇒ Object
The quality factor associated with the media range, which is used to determine the order of preference.
66 67 68 |
# File 'lib/protocol/http/header/accept.rb', line 66 def quality_factor parameters.fetch("q", 1.0).to_f end |
#to_s ⇒ Object Also known as: to_str
The string representation of the media range, including the type, subtype, and any parameters.
57 58 59 |
# File 'lib/protocol/http/header/accept.rb', line 57 def to_s "#{type}/#{subtype}#{parameters_string}" end |