Parent

Class/Module Index [+]

Quicksearch

Merb::AcceptType

Attributes

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

Public Class Methods

new(entry,index) click to toggle source

Parameters

entry<String>

The accept type pattern

index<Fixnum>

The index used for sorting accept types. A lower value indicates higher priority.

:api: private

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

Public Instance Methods

<=>(entry) click to toggle source

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

# File lib/merb-core/controller/mixins/responder.rb, line 440
def <=>(entry)
  if entry.quality == quality
    @index <=> entry.index
  else
    entry.quality <=> @quality
  end
end
==(entry) click to toggle source

An alias for eql?.

:api: private

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

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

# File lib/merb-core/controller/mixins/responder.rb, line 458
def eql?(entry)
  synonyms.include?(entry.media_range)
end
hash() click to toggle source

Returns

Fixnum

A hash based on the super range.

:api: private

# File lib/merb-core/controller/mixins/responder.rb, line 471
def hash; super_range.hash; end
mime() click to toggle source

:api: private

# File lib/merb-core/controller/mixins/responder.rb, line 488
def mime
  @mime ||= Merb.available_mime_types[Merb::ResponderMixin::MIMES[@media_range]]
end
super_range() click to toggle source

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

# File lib/merb-core/controller/mixins/responder.rb, line 498
def super_range
  synonyms.first || @media_range
end
synonyms() click to toggle source

Returns

Array

All Accept header values, such as "text/html", that match this type.

:api: private

# File lib/merb-core/controller/mixins/responder.rb, line 478
def synonyms
  return @syns if @syns
  if _mime = mime
    @syns = _mime[:accepts]
  else
    @syns = []
  end
end
to_s() click to toggle source

Returns

String

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

:api: private

# File lib/merb-core/controller/mixins/responder.rb, line 515
def to_s
  @media_range
end
to_sym() click to toggle source

Returns

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

:api: private

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.