Class: Sinatra::Request::AcceptEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ AcceptEntry

Returns a new instance of AcceptEntry.



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 76

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 = Hash[params]
  @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) ⇒ Object



110
111
112
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 110

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

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



74
75
76
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 74

def params
  @params
end

Instance Method Details

#<=>(other) ⇒ Object



89
90
91
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 89

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

#priorityObject



93
94
95
96
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 93

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

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 106

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

#to_s(full = false) ⇒ Object



102
103
104
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 102

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

#to_strObject



98
99
100
# File 'lib/vendor/sinatra-1.4.4/lib/sinatra/base.rb', line 98

def to_str
  @type
end