123456789_123456789_123456789_123456789_123456789_

Class: Sinatra::Request::AcceptEntry

Relationships & Source Files
Inherits: Object
Defined in: lib/sinatra/base.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(entry) ⇒ AcceptEntry

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 95

def initialize(entry)
  params = entry.scan(HEADER_PARAM).map! do |s|
    key, value = s.strip.split('=', 2)
    value = value[1..-2].gsub(/\\(.)/, '\1') if value.start_with?('"')
    [key, value]
  end

  @entry  = entry
  @type   = entry[/[^;]+/].delete(' ')
  @params = params.to_h
  @q      = @params.delete('q') { 1.0 }.to_f
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 129

def method_missing(*args, &block)
  to_str.send(*args, &block)
end

Instance Attribute Details

#entry (readonly)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 93

attr_reader :entry

#params (rw)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 92

attr_accessor :params

Instance Method Details

#<=>(other)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 108

def <=>(other)
  other.priority <=> priority
end

#priority

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 112

def priority
  # We sort in descending order; better matches should be higher.
  [@q, -@type.count('*'), @params.size]
end

#respond_to?(*args) ⇒ Boolean

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 125

def respond_to?(*args)
  super || to_str.respond_to?(*args)
end

#to_s(full = false)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 121

def to_s(full = false)
  full ? entry : to_str
end

#to_str

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 117

def to_str
  @type
end