Class: Sinatra::Request::AcceptEntry
- Inherits:
-
Object
- Object
- Sinatra::Request::AcceptEntry
show all
- Defined in:
- lib/sinatra/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AcceptEntry.
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/sinatra/base.rb', line 89
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
123
124
125
|
# File 'lib/sinatra/base.rb', line 123
def method_missing(*args, &block)
to_str.send(*args, &block)
end
|
Instance Attribute Details
#entry ⇒ Object
Returns the value of attribute entry.
87
88
89
|
# File 'lib/sinatra/base.rb', line 87
def entry
@entry
end
|
#params ⇒ Object
Returns the value of attribute params.
86
87
88
|
# File 'lib/sinatra/base.rb', line 86
def params
@params
end
|
Instance Method Details
#<=>(other) ⇒ Object
102
103
104
|
# File 'lib/sinatra/base.rb', line 102
def <=>(other)
other.priority <=> self.priority
end
|
#priority ⇒ Object
106
107
108
109
|
# File 'lib/sinatra/base.rb', line 106
def priority
[ @q, -@type.count('*'), @params.size ]
end
|
#respond_to?(*args) ⇒ Boolean
119
120
121
|
# File 'lib/sinatra/base.rb', line 119
def respond_to?(*args)
super or to_str.respond_to?(*args)
end
|
#to_s(full = false) ⇒ Object
115
116
117
|
# File 'lib/sinatra/base.rb', line 115
def to_s(full = false)
full ? entry : to_str
end
|
#to_str ⇒ Object
111
112
113
|
# File 'lib/sinatra/base.rb', line 111
def to_str
@type
end
|