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.
76 77 78 79 |
# File 'lib/rack/accept_media_types.rb', line 76 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") ] )
74 75 76 |
# File 'lib/rack/accept_media_types.rb', line 74 def quality @quality end |
#range ⇒ Object
media-range = ( “/”
| ( type "/" "*" )
| ( type "/" subtype )
) *( ";" parameter )
70 71 72 |
# File 'lib/rack/accept_media_types.rb', line 70 def range @range end |
Instance Method Details
#<=>(type) ⇒ Object
81 82 83 |
# File 'lib/rack/accept_media_types.rb', line 81 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.”
90 91 92 |
# File 'lib/rack/accept_media_types.rb', line 90 def valid? self.quality.between?(0.1, 1) end |