Class: Cyberweb::REST::AcceptEntry
- Inherits:
-
Object
- Object
- Cyberweb::REST::AcceptEntry
- Defined in:
- lib/cyberweb/REST/base/accept_entry.rb
Overview
Cyberweb::REST::AcceptEntry
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
# === <=> ========================================================================= #.
-
#entry? ⇒ Boolean
(also: #entry)
# === entry? ========================================================================= #.
-
#initialize(entry) ⇒ AcceptEntry
constructor
# === initialize ========================================================================= #.
-
#method_missing(*args, &block) ⇒ Object
# === method_missing ========================================================================= #.
-
#priority ⇒ Object
# === priority ========================================================================= #.
-
#respond_to?(*args) ⇒ Boolean
# === respond_to? ========================================================================= #.
-
#to_s(full = false) ⇒ Object
# === to_s ========================================================================= #.
-
#to_str ⇒ Object
# === to_str ========================================================================= #.
Constructor Details
#initialize(entry) ⇒ AcceptEntry
#
initialize
#
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 22 def initialize(entry) params = entry.scan(HEADER_PARAM).map! { |s| key, value = s.strip.split('=', 2) if value.start_with?('"') value = value[1..-2].gsub(/\\(.)/, '\1') end [key, value] } @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
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
17 18 19 |
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 17 def params @params end |
Instance Method Details
#<=>(other) ⇒ Object
#
<=>
#
40 41 42 |
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 40 def <=>(other) other.priority <=> priority end |
#entry? ⇒ Boolean Also known as: entry
#
entry?
#
80 81 82 |
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 80 def entry? @entry end |
#priority ⇒ Object
#
priority
#
47 48 49 50 51 52 53 54 |
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 47 def priority # ======================================================================= # # We sort in descending order; better matches should be higher. # ======================================================================= # [ @q, -@type.count('*'), @params.size ] end |
#respond_to?(*args) ⇒ Boolean
#
respond_to?
#
73 74 75 |
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 73 def respond_to?(*args) super || to_str.respond_to?(*args) end |
#to_s(full = false) ⇒ Object
#
to_s
#
66 67 68 |
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 66 def to_s(full = false) full ? entry : to_str end |
#to_str ⇒ Object
#
to_str
#
59 60 61 |
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 59 def to_str @type end |