Class: Rack::AcceptMediaTypes::AcceptMediaType

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

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#qualityObject

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

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


74
75
76
# File 'lib/rack/accept_media_types.rb', line 74

def quality
  @quality
end

#rangeObject

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.”

Returns:

  • (Boolean)


90
91
92
# File 'lib/rack/accept_media_types.rb', line 90

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