Class: Rack::AcceptMediaTypes::AcceptMediaType
- Inherits:
-
Object
- Object
- Rack::AcceptMediaTypes::AcceptMediaType
- Includes:
- Comparable
- Defined in:
- lib/rack/accept_media_types.rb
Overview
Instance Attribute Summary collapse
-
#quality ⇒ Object
qvalue = ( “0” [ “.” 0*3DIGIT ] ) | ( “1” [ “.” 0*3(“0”) ] ).
-
#range ⇒ Object
media-range = ( “/” | ( type “/” “*” ) | ( type “/” subtype ) ) *( “;” parameter ).
Instance Method Summary collapse
- #<=>(type) ⇒ Object
-
#initialize(type) ⇒ AcceptMediaType
constructor
A new instance of AcceptMediaType.
-
#valid? ⇒ Boolean
“A weight is normalized to a real number in the range 0 through 1, where 0 is the minimum and 1 the maximum value.
Constructor Details
#initialize(type) ⇒ AcceptMediaType
Returns a new instance of AcceptMediaType.
99 100 101 102 |
# File 'lib/rack/accept_media_types.rb', line 99 def initialize(type) self.range, *params = type.split(';') self.quality = extract_quality(params) end |
Instance Attribute Details
#quality ⇒ Object
qvalue = ( “0” [ “.” 0*3DIGIT ] )
| ( "1" [ "." 0*3("0") ] )
97 98 99 |
# File 'lib/rack/accept_media_types.rb', line 97 def quality @quality end |
#range ⇒ Object
media-range = ( “/”
| ( type "/" "*" )
| ( type "/" subtype )
) *( ";" parameter )
93 94 95 |
# File 'lib/rack/accept_media_types.rb', line 93 def range @range end |
Instance Method Details
#<=>(type) ⇒ Object
104 105 106 |
# File 'lib/rack/accept_media_types.rb', line 104 def <=>(type) self.quality <=> type.quality end |
#valid? ⇒ Boolean
“A weight is normalized to a real number in the range 0 through 1, where 0 is the minimum and 1 the maximum value. If a parameter has a quality value of 0, then content with this parameter is ‘not acceptable’ for the client.”
113 114 115 |
# File 'lib/rack/accept_media_types.rb', line 113 def valid? self.quality.between?(0.1, 1) end |