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.



42
43
44
45
46
47
# File 'lib/action_controller/mime_type.rb', line 42

def initialize(order, name, q=nil)
  @order = order
  @name = name.strip
  q ||= 0.0 if @name == Mime::ALL # default wilcard match to end of list
  @q = ((q || 1.0).to_f * 100).to_i
end

Instance Attribute Details

#nameObject

:nodoc:



40
41
42
# File 'lib/action_controller/mime_type.rb', line 40

def name
  @name
end

#orderObject

:nodoc:



40
41
42
# File 'lib/action_controller/mime_type.rb', line 40

def order
  @order
end

#qObject

:nodoc:



40
41
42
# File 'lib/action_controller/mime_type.rb', line 40

def q
  @q
end

Instance Method Details

#<=>(item) ⇒ Object



53
54
55
56
57
# File 'lib/action_controller/mime_type.rb', line 53

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

#==(item) ⇒ Object



59
60
61
# File 'lib/action_controller/mime_type.rb', line 59

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

#to_sObject



49
50
51
# File 'lib/action_controller/mime_type.rb', line 49

def to_s
  @name
end