Class: Sinatra::Request::MimeTypeEntry
- Inherits:
-
Object
- Object
- Sinatra::Request::MimeTypeEntry
- Defined in:
- lib/sinatra/base.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #accepts?(entry) ⇒ Boolean
-
#initialize(entry) ⇒ MimeTypeEntry
constructor
A new instance of MimeTypeEntry.
- #matches_params?(params) ⇒ Boolean
- #to_str ⇒ Object
Constructor Details
#initialize(entry) ⇒ MimeTypeEntry
Returns a new instance of MimeTypeEntry.
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/sinatra/base.rb', line 129 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
#params ⇒ Object (readonly)
Returns the value of attribute params.
127 128 129 |
# File 'lib/sinatra/base.rb', line 127 def params @params end |
Instance Method Details
#accepts?(entry) ⇒ Boolean
140 141 142 |
# File 'lib/sinatra/base.rb', line 140 def accepts?(entry) File.fnmatch(entry, self) && matches_params?(entry.params) end |
#matches_params?(params) ⇒ Boolean
148 149 150 151 152 |
# File 'lib/sinatra/base.rb', line 148 def matches_params?(params) return true if @params.empty? params.all? { |k,v| !@params.has_key?(k) || @params[k] == v } end |
#to_str ⇒ Object
144 145 146 |
# File 'lib/sinatra/base.rb', line 144 def to_str @type end |