Class Merb::AcceptType
In: merb-core/lib/merb-core/controller/mixins/responder.rb
Parent: Object

Methods

<=>   ==   eql?   hash   mime   new   super_range   synonyms   to_s   to_sym  

Attributes

index  [R] 
media_range  [R] 
quality  [R] 
sub_type  [R] 
type  [R] 

Public Class methods

Parameters

entry<String>:The accept type pattern
index<Fixnum>:The index used for sorting accept types. A lower value indicates higher priority.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 417
417:     def initialize(entry,index)
418:       @index = index
419:       
420:       entry =~ /\s*([^;\s]*)\s*(;\s*q=\s*(.*))?/
421:       @media_range, quality = $1, $3
422:       
423:       @type, @sub_type = @media_range.split(%r{/})
424:       (quality ||= 0.0) if @media_range == "*/*"
425:       @quality = quality ? (quality.to_f * 100).to_i : 100
426:       @quality *= (mime && mime[:default_quality] || 1)
427:     end

Public Instance methods

Compares two accept types for sorting purposes.

Parameters

entry<AcceptType>:The accept type to compare.

Returns

Fixnum:-1, 0 or 1, depending on whether entry has a lower, equal or higher priority than the accept type being compared.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 440
440:     def <=>(entry)
441:       if entry.quality == quality
442:         @index <=> entry.index
443:       else
444:         entry.quality <=> @quality
445:       end
446:     end

An alias for eql?.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 465
465:     def ==(entry); eql?(entry); end

Parameters

entry<AcceptType>:The accept type to compare.

Returns

Boolean:True if the accept types are equal, i.e. if the synonyms for this accept type includes the entry media range.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 458
458:     def eql?(entry)
459:       synonyms.include?(entry.media_range)
460:     end

Returns

Fixnum:A hash based on the super range.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 471
471:     def hash; super_range.hash; end

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 488
488:     def mime
489:       @mime ||= Merb.available_mime_types[Merb::ResponderMixin::MIMES[@media_range]]
490:     end

Returns

String:The primary media range for this accept type, i.e. either the first synonym or, if none exist, the media range.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 498
498:     def super_range
499:       synonyms.first || @media_range
500:     end

Returns

Array[String]:All Accept header values, such as "text/html", that match this type.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 478
478:     def synonyms
479:       return @syns if @syns
480:       if _mime = mime
481:         @syns = _mime[:accepts]
482:       else
483:         @syns = []
484:       end
485:     end

Returns

String:The accept type as a string, i.e. the media range.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 515
515:     def to_s
516:       @media_range
517:     end

Returns

Symbol: The type as a symbol, e.g. :html.

:api: private

[Source]

     # File merb-core/lib/merb-core/controller/mixins/responder.rb, line 506
506:     def to_sym
507:       Merb.available_mime_types.select{|k,v| 
508:         v[:accepts] == synonyms || v[:accepts][0] == synonyms[0]}.flatten.first
509:     end

[Validate]