README.md in accept_headers-0.0.4 vs README.md in accept_headers-0.0.5

- old
+ new

@@ -61,20 +61,26 @@ AcceptHeaders::MediaType.new('text', 'html', q: 0.4, params: { 'level' => '2' }), AcceptHeaders::MediaType.new('text', '*', q: 0.3) ] ``` -`#negotiate` takes a string of media types supported (by your API or route/controller) and returns the best match as a `MediaType`. This will first check the available list for any matching media types with a `q` of 0 and return `nil` if there is a match. Then it'll look to the highest `q` values and look for matches in descending `q` value order and return the first match account for wildcards. +`#negotiate` takes a string of media types supported (by your API or route/controller) and returns the best match as a `MediaType`. This will first check the available list for any matching media types with a `q` of 0 and return `nil` if there is a match. Then it'll look to the highest `q` values and look for matches in descending `q` value order and return the first match (accounting for wildcards). Finally, if there are no matches, it returns `nil`. ```ruby -media_type.negotiate('text/html') +media_types.negotiate('text/html') # Returns: AcceptHeaders::MediaType.new('text', 'html', params: { 'level' => '1' }) ``` +`#accept?`: + +```ruby +media_types.accept?('text/html') # true +``` + ### Accept-Encoding `AcceptHeader::Charset::Encoding`: ```ruby @@ -84,26 +90,35 @@ # Returns: [ AcceptHeaders::Encoding.new('gzip'), - AcceptHeaders::Encoding.new('identity'), AcceptHeaders::Encoding.new('compress', q: 0.8), AcceptHeaders::Encoding.new('deflate', q: 0.5) ] ``` `#negotiate`: ```ruby -encodings.negotiate('identity') +encodings.negotiate('gzip') # Returns: -AcceptHeaders::Encoding.new('identity') +AcceptHeaders::Encoding.new('gzip') ``` +`#accept?`: + +```ruby +encodings.accept?('gzip') # true + +# Identity is accepted as long as it's not explicitly rejected 'identity;q=0' + +encodings.accept?('identity') # true +``` + ### Accept-Language `Accept::Language::Negotiator`: ```ruby @@ -128,10 +143,16 @@ # Returns: AcceptHeaders::Language.new('en', 'us') ``` -## Todo +`#accept?`: + +```ruby +languages.accept?('en-gb') # true +``` + +## TODO * Write rack middleware * More edge case tests * Add rdoc