Class: Cyberweb::REST::AcceptEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberweb/REST/base/accept_entry.rb

Overview

Cyberweb::REST::AcceptEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#method_missing(*args, &block) ⇒ Object

#

method_missing

#


87
88
89
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 87

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

Instance Attribute Details

#paramsObject

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?

#

Returns:

  • (Boolean)


80
81
82
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 80

def entry?
  @entry
end

#priorityObject

#

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?

#

Returns:

  • (Boolean)


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_strObject

#

to_str

#


59
60
61
# File 'lib/cyberweb/REST/base/accept_entry.rb', line 59

def to_str
  @type
end