Class: Sinatra::Request::MimeTypeEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ MimeTypeEntry

Returns a new instance of MimeTypeEntry.


131
132
133
134
135
136
137
138
139
140
# File 'lib/sinatra/base.rb', line 131

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

  @type   = entry[/[^;]+/].delete(' ')
  @params = Hash[params]
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.


129
130
131
# File 'lib/sinatra/base.rb', line 129

def params
  @params
end

Instance Method Details

#accepts?(entry) ⇒ Boolean

Returns:

  • (Boolean)

142
143
144
# File 'lib/sinatra/base.rb', line 142

def accepts?(entry)
  File.fnmatch(entry, self) && matches_params?(entry.params)
end

#matches_params?(params) ⇒ Boolean

Returns:

  • (Boolean)

150
151
152
153
154
# File 'lib/sinatra/base.rb', line 150

def matches_params?(params)
  return true if @params.empty?

  params.all? { |k,v| !@params.has_key?(k) || @params[k] == v }
end

#to_strObject


146
147
148
# File 'lib/sinatra/base.rb', line 146

def to_str
  @type
end