Class: Sinatra::Request::AcceptEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ AcceptEntry

Returns a new instance of AcceptEntry.



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 90

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



124
125
126
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 124

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

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



88
89
90
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 88

def entry
  @entry
end

#paramsObject

Returns the value of attribute params.



87
88
89
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 87

def params
  @params
end

Instance Method Details

#<=>(other) ⇒ Object



103
104
105
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 103

def <=>(other)
  other.priority <=> priority
end

#priorityObject



107
108
109
110
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 107

def priority
  # We sort in descending order; better matches should be higher.
  [@q, -@type.count('*'), @params.size]
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 120

def respond_to?(*args)
  super || to_str.respond_to?(*args)
end

#to_s(full = false) ⇒ Object



116
117
118
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 116

def to_s(full = false)
  full ? entry : to_str
end

#to_strObject



112
113
114
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.5/lib/sinatra/base.rb', line 112

def to_str
  @type
end