Class: Mime::Type::AcceptItem
- Inherits:
-
Object
- Object
- Mime::Type::AcceptItem
- Defined in:
- lib/classy_resources/mime_type.rb
Overview
A simple helper class used in parsing the accept header
Instance Attribute Summary collapse
-
#name ⇒ Object
:nodoc:.
-
#order ⇒ Object
:nodoc:.
-
#q ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #<=>(item) ⇒ Object
- #==(item) ⇒ Object
-
#initialize(order, name, q = nil) ⇒ AcceptItem
constructor
A new instance of AcceptItem.
- #to_s ⇒ Object
Constructor Details
#initialize(order, name, q = nil) ⇒ AcceptItem
Returns a new instance of AcceptItem.
34 35 36 37 38 39 |
# File 'lib/classy_resources/mime_type.rb', line 34 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
#name ⇒ Object
:nodoc:
32 33 34 |
# File 'lib/classy_resources/mime_type.rb', line 32 def name @name end |
#order ⇒ Object
:nodoc:
32 33 34 |
# File 'lib/classy_resources/mime_type.rb', line 32 def order @order end |
#q ⇒ Object
:nodoc:
32 33 34 |
# File 'lib/classy_resources/mime_type.rb', line 32 def q @q end |
Instance Method Details
#<=>(item) ⇒ Object
45 46 47 48 49 |
# File 'lib/classy_resources/mime_type.rb', line 45 def <=>(item) result = item.q <=> q result = order <=> item.order if result == 0 result end |
#==(item) ⇒ Object
51 52 53 |
# File 'lib/classy_resources/mime_type.rb', line 51 def ==(item) name == (item.respond_to?(:name) ? item.name : item) end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/classy_resources/mime_type.rb', line 41 def to_s @name end |