Class: Mime::Type::AcceptItem

Inherits:
Object
  • Object
show all
Defined in:
lib/action_controller/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(order, name, q = nil) ⇒ AcceptItem

Returns a new instance of AcceptItem.


7
8
9
10
11
12
# File 'lib/action_controller/mime_type.rb', line 7

def initialize(order, name, q=nil)
  @order = order
  @name = name.strip
  q ||= 0.0 if @name == "*/*" # default "*/*" to end of list
  @q = ((q || 1.0).to_f * 100).to_i
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


5
6
7
# File 'lib/action_controller/mime_type.rb', line 5

def name
  @name
end

#orderObject

Returns the value of attribute order


5
6
7
# File 'lib/action_controller/mime_type.rb', line 5

def order
  @order
end

#qObject

Returns the value of attribute q


5
6
7
# File 'lib/action_controller/mime_type.rb', line 5

def q
  @q
end

Instance Method Details

#<=>(item) ⇒ Object


18
19
20
21
22
# File 'lib/action_controller/mime_type.rb', line 18

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

#==(item) ⇒ Object


24
25
26
# File 'lib/action_controller/mime_type.rb', line 24

def ==(item)
  name == (item.respond_to?(:name) ? item.name : item)
end

#to_sObject


14
15
16
# File 'lib/action_controller/mime_type.rb', line 14

def to_s
  @name
end