Class: Mime::Type::AcceptItem

Inherits:
Object
  • Object
show all
Defined in:
lib/action_dispatch/http/mime_type.rb

Overview

A simple helper class used in parsing the accept header.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, name, q = nil) ⇒ AcceptItem

Returns a new instance of AcceptItem.



94
95
96
97
98
99
# File 'lib/action_dispatch/http/mime_type.rb', line 94

def initialize(index, name, q = nil)
  @index = index
  @name = name
  q ||= 0.0 if @name == "*/*" # Default wildcard match to end of list.
  @q = ((q || 1.0).to_f * 100).to_i
end

Instance Attribute Details

#indexObject

:nodoc:



91
92
93
# File 'lib/action_dispatch/http/mime_type.rb', line 91

def index
  @index
end

#nameObject Also known as: to_s

:nodoc:



91
92
93
# File 'lib/action_dispatch/http/mime_type.rb', line 91

def name
  @name
end

#qObject

:nodoc:



91
92
93
# File 'lib/action_dispatch/http/mime_type.rb', line 91

def q
  @q
end

Instance Method Details

#<=>(item) ⇒ Object



101
102
103
104
105
# File 'lib/action_dispatch/http/mime_type.rb', line 101

def <=>(item)
  result = item.q <=> @q
  result = @index <=> item.index if result == 0
  result
end