Class: Safrano::Request::AcceptEntry
- Inherits:
-
Object
- Object
- Safrano::Request::AcceptEntry
- Defined in:
- lib/safrano/request.rb
Overview
borowed from Sinatra
Instance Attribute Summary collapse
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(entry) ⇒ AcceptEntry
constructor
A new instance of AcceptEntry.
- #priority ⇒ Object
- #respond_to?(*args) ⇒ Boolean
- #to_str ⇒ Object
Constructor Details
#initialize(entry) ⇒ AcceptEntry
Returns a new instance of AcceptEntry.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/safrano/request.rb', line 72 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 |
Instance Attribute Details
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
70 71 72 |
# File 'lib/safrano/request.rb', line 70 def entry @entry end |
#params ⇒ Object
Returns the value of attribute params.
69 70 71 |
# File 'lib/safrano/request.rb', line 69 def params @params end |
Instance Method Details
#<=>(other) ⇒ Object
85 86 87 |
# File 'lib/safrano/request.rb', line 85 def <=>(other) other.priority <=> priority end |
#priority ⇒ Object
89 90 91 92 |
# File 'lib/safrano/request.rb', line 89 def priority # We sort in descending order; better matches should be higher. [@q, -@type.count('*'), @params.size] end |
#respond_to?(*args) ⇒ Boolean
94 95 96 |
# File 'lib/safrano/request.rb', line 94 def respond_to?(*args) super || to_str.respond_to?(*args) end |
#to_str ⇒ Object
98 99 100 |
# File 'lib/safrano/request.rb', line 98 def to_str @type end |