Class: Rack::AcceptMediaTypes::AcceptMediaType

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/sinatra/accept_media_types.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ AcceptMediaType

Returns a new instance of AcceptMediaType.



99
100
101
102
# File 'lib/sinatra/accept_media_types.rb', line 99

def initialize(type)
  self.range, *params = type.split(';')
  self.quality = extract_quality(params)
end

Instance Attribute Details

#qualityObject

qvalue = ( “0” [ “.” 0*3DIGIT ] )

| ( "1" [ "." 0*3("0") ] )


97
98
99
# File 'lib/sinatra/accept_media_types.rb', line 97

def quality
  @quality
end

#rangeObject

media-range = ( “/

| ( type "/" "*" )
| ( type "/" subtype )
) *( ";" parameter )


93
94
95
# File 'lib/sinatra/accept_media_types.rb', line 93

def range
  @range
end

Instance Method Details

#<=>(type) ⇒ Object



104
105
106
# File 'lib/sinatra/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.”

Returns:

  • (Boolean)


113
114
115
# File 'lib/sinatra/accept_media_types.rb', line 113

def valid?
  self.quality.between?(0.1, 1)
end