class MediaRange
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.
Definitions
def initialize(type, subtype = "*", parameters = {})
Create a new media range.
Signature
-
parameter
typeString the type of the media range.
-
parameter
subtypeString the subtype of the media range.
-
parameter
parametersHash the parameters associated with the media range.
Implementation
def initialize(type, subtype = "*", parameters = {})
super(type, subtype, parameters)
end
def <=>(other)
Compare the media range with another media range or a string, based on the quality factor.
Implementation
def <=> other
other.quality_factor <=> self.quality_factor
end
def to_s
The string representation of the media range, including the type, subtype, and any parameters.
Implementation
def to_s
"#{type}/#{subtype}#{parameters_string}"
end
def quality_factor
The quality factor associated with the media range, which is used to determine the order of preference.
Signature
-
returns
Float the quality factor, which defaults to 1.0 if not specified.
Implementation
def quality_factor
parameters.fetch("q", 1.0).to_f
end