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.
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/sinatra/base.rb', line 98
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) ⇒ Object
132
133
134
|
# File 'lib/sinatra/base.rb', line 132
def method_missing(*args, &block)
to_str.send(*args, &block)
end
|
Instance Attribute Details
#entry ⇒ Object
Returns the value of attribute entry.
96
97
98
|
# File 'lib/sinatra/base.rb', line 96
def entry
@entry
end
|
#params ⇒ Object
Returns the value of attribute params.
95
96
97
|
# File 'lib/sinatra/base.rb', line 95
def params
@params
end
|
Instance Method Details
#<=>(other) ⇒ Object
111
112
113
|
# File 'lib/sinatra/base.rb', line 111
def <=>(other)
other.priority <=> priority
end
|
#priority ⇒ Object
115
116
117
118
|
# File 'lib/sinatra/base.rb', line 115
def priority
[@q, -@type.count('*'), @params.size]
end
|
#respond_to?(*args) ⇒ Boolean
128
129
130
|
# File 'lib/sinatra/base.rb', line 128
def respond_to?(*args)
super || to_str.respond_to?(*args)
end
|
#to_s(full = false) ⇒ Object
124
125
126
|
# File 'lib/sinatra/base.rb', line 124
def to_s(full = false)
full ? entry : to_str
end
|
#to_str ⇒ Object
120
121
122
|
# File 'lib/sinatra/base.rb', line 120
def to_str
@type
end
|