Class: Rack::Request::AcceptableMediaTypes::MediaType
- Inherits:
-
Object
- Object
- Rack::Request::AcceptableMediaTypes::MediaType
- Includes:
- Comparable
- Defined in:
- lib/rack/acceptable.rb
Constant Summary collapse
- ANY =
"*"
Instance Attribute Summary collapse
-
#media_type ⇒ Object
Returns the value of attribute media_type.
-
#quality ⇒ Object
qvalue = ( “0” [ “.” 0*3DIGIT ] ) | ( “1” [ “.” 0*3(“0”) ] ).
-
#range ⇒ Object
media-range = ( “/” | ( type “/” “*” ) | ( type “/” subtype ) ) *( “;” parameter ).
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other_media_type) ⇒ Object
-
#initialize(media_type) ⇒ MediaType
constructor
A new instance of MediaType.
- #inspect ⇒ Object
- #subtype ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
-
#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(media_type) ⇒ MediaType
Returns a new instance of MediaType.
100 101 102 |
# File 'lib/rack/acceptable.rb', line 100 def initialize(media_type) @media_type = media_type end |
Instance Attribute Details
#media_type ⇒ Object
Returns the value of attribute media_type.
96 97 98 |
# File 'lib/rack/acceptable.rb', line 96 def media_type @media_type end |
#quality ⇒ Object
qvalue = ( “0” [ “.” 0*3DIGIT ] ) | ( “1” [ “.” 0*3(“0”) ] )
114 115 116 |
# File 'lib/rack/acceptable.rb', line 114 def quality @quality end |
#range ⇒ Object
media-range = ( “/” | ( type “/” “*” ) | ( type “/” subtype ) ) *( “;” parameter )
108 109 110 |
# File 'lib/rack/acceptable.rb', line 108 def range @range end |
Instance Method Details
#<=>(other) ⇒ Object
118 119 120 |
# File 'lib/rack/acceptable.rb', line 118 def <=>(other) other.quality <=> quality end |
#==(other_media_type) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rack/acceptable.rb', line 122 def ==(other_media_type) return false unless other_media_type.is_a?(String) || other_media_type.is_a?(MediaType) other_media_type = MediaType.new(other_media_type) unless other_media_type.is_a?(MediaType) if type == ANY true elsif type == other_media_type.type subtype == ANY || subtype == other_media_type.subtype else false end end |
#inspect ⇒ Object
135 136 137 |
# File 'lib/rack/acceptable.rb', line 135 def inspect %Q{#<#{self.class}:0x%1x #{to_s}>} % object_id end |
#subtype ⇒ Object
156 157 158 |
# File 'lib/rack/acceptable.rb', line 156 def subtype @subtype ||= range.split('/').last end |
#to_s ⇒ Object
139 140 141 |
# File 'lib/rack/acceptable.rb', line 139 def to_s @media_type end |
#type ⇒ Object
152 153 154 |
# File 'lib/rack/acceptable.rb', line 152 def type @type ||= range.split('/').first 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.”
148 149 150 |
# File 'lib/rack/acceptable.rb', line 148 def valid? quality > 0 && quality <= 1 end |