http-accept 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.simplecov +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +72 -0
- data/Rakefile +8 -0
- data/http-accept.gemspec +23 -0
- data/lib/http/accept.rb +34 -0
- data/lib/http/accept/languages.rb +70 -0
- data/lib/http/accept/media_types.rb +77 -0
- data/lib/http/accept/parse_error.rb +26 -0
- data/lib/http/accept/quoted_string.rb +53 -0
- data/lib/http/accept/sort.rb +30 -0
- data/lib/http/accept/version.rb +25 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b3e639112f0987204fc1c5f221df4a5f5f066742
|
4
|
+
data.tar.gz: 0285743cfe72774a0c92bb7767d5cb0aaf8131c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e642fbaa9710c53966260df269b7b5c7c21d8b2f702633ab94667c506235656f5a0cdadfc6f3841b35f8cef86b38a5ed6dc4c33c19a19f39943bbae01d563f3
|
7
|
+
data.tar.gz: f0fd1541954d7c65ad388c4e7cb0f7511d2460159281bdbf2273140323cceda56af1a03fe670d8b593a2224400f7895fd6c16db55eff3d79964929c8d7c297ff
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# HTTP::Accept
|
2
|
+
|
3
|
+
Provides a robust set of parsers for dealing with Accept and Accept-Language HTTP headers.
|
4
|
+
|
5
|
+
Current `Accept-Encoding:` and `Accept-Charset:` are not supported. This is because they are not particularly useful headers, but PRs are welcome.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'http-accept'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install http-accept
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Here are some examples of how to parse various headers.
|
24
|
+
|
25
|
+
### Parsing Accept: headers
|
26
|
+
|
27
|
+
media_types = HTTP::Accept::MediaTypes.parse("text/html;q=0.5, application/json; version=1")
|
28
|
+
|
29
|
+
expect(media_types[0].mime_type).to be == "application/json"
|
30
|
+
expect(media_types[0].parameters).to be == {'version' => '1'}
|
31
|
+
expect(media_types[1].mime_type).to be == "text/html"
|
32
|
+
expect(media_types[1].parameters).to be == {'q' => '0.5'}
|
33
|
+
|
34
|
+
### Parsing Accept-Language: headers
|
35
|
+
|
36
|
+
languages = HTTP::Accept::Language.parse("da, en-gb;q=0.8, en;q=0.7")
|
37
|
+
|
38
|
+
expect(languages[0].locale).to be == "da"
|
39
|
+
expect(languages[1].locale).to be == "en-gb"
|
40
|
+
expect(languages[2].locale).to be == "en"`
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
Released under the MIT license.
|
53
|
+
|
54
|
+
Copyright, 2016, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
55
|
+
|
56
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
57
|
+
of this software and associated documentation files (the "Software"), to deal
|
58
|
+
in the Software without restriction, including without limitation the rights
|
59
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
60
|
+
copies of the Software, and to permit persons to whom the Software is
|
61
|
+
furnished to do so, subject to the following conditions:
|
62
|
+
|
63
|
+
The above copyright notice and this permission notice shall be included in
|
64
|
+
all copies or substantial portions of the Software.
|
65
|
+
|
66
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
67
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
68
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
69
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
70
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
71
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
72
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
data/http-accept.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'http/accept/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "http-accept"
|
8
|
+
spec.version = HTTP::Accept::VERSION
|
9
|
+
spec.authors = ["Samuel Williams"]
|
10
|
+
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
|
+
|
12
|
+
spec.summary = %q{Parse Accept and Accept-Language HTTP headers.}
|
13
|
+
spec.homepage = "https://github.com/ioquatix/http-accept"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
end
|
data/lib/http/accept.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require "http/accept/version"
|
22
|
+
|
23
|
+
require_relative 'accept/version'
|
24
|
+
|
25
|
+
# Accept: header
|
26
|
+
require_relative 'accept/media_types'
|
27
|
+
|
28
|
+
# Accept-Language: header
|
29
|
+
require_relative 'accept/languages'
|
30
|
+
|
31
|
+
module HTTP
|
32
|
+
module Accept
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'strscan'
|
22
|
+
|
23
|
+
require_relative 'parse_error'
|
24
|
+
require_relative 'sort'
|
25
|
+
|
26
|
+
module HTTP
|
27
|
+
module Accept
|
28
|
+
class Languages
|
29
|
+
LOCALE = /\*|[A-Z]{1,8}(-[A-Z]{1,8})*/i
|
30
|
+
|
31
|
+
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9
|
32
|
+
QVALUE = /0(\.[0-9]{0,3})?|1(\.[0]{0,3})?/
|
33
|
+
|
34
|
+
LANGUAGE_RANGE = /(?<locale>#{LOCALE})(;q=(?<q>#{QVALUE}))?/
|
35
|
+
|
36
|
+
class LanguageRange < Struct.new(:locale, :q)
|
37
|
+
def quality_factor
|
38
|
+
(q || 1.0).to_f
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.parse(scanner)
|
42
|
+
return to_enum(:parse, scanner) unless block_given?
|
43
|
+
|
44
|
+
while scanner.scan(LANGUAGE_RANGE)
|
45
|
+
yield self.new(scanner[:locale], scanner[:q])
|
46
|
+
|
47
|
+
# Are there more?
|
48
|
+
return unless scanner.scan(/\s*,\s*/)
|
49
|
+
end
|
50
|
+
|
51
|
+
raise ParseError.new("Could not parse entire string!") unless scanner.eos?
|
52
|
+
end
|
53
|
+
|
54
|
+
# If the user ask for 'en', this satisfies any language that begins with 'en-'
|
55
|
+
def prefix_of? other
|
56
|
+
other.start_with(locale)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.parse(text)
|
61
|
+
scanner = StringScanner.new(text)
|
62
|
+
|
63
|
+
languages = LanguageRange.parse(scanner)
|
64
|
+
|
65
|
+
return Sort.by_quality_factor(languages)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'strscan'
|
22
|
+
|
23
|
+
require_relative 'parse_error'
|
24
|
+
require_relative 'quoted_string'
|
25
|
+
require_relative 'sort'
|
26
|
+
|
27
|
+
module HTTP
|
28
|
+
module Accept
|
29
|
+
class MediaTypes
|
30
|
+
# According to https://tools.ietf.org/html/rfc7231#section-5.3.2
|
31
|
+
MIME_TYPE = /(#{TOKEN})\/(#{TOKEN})/
|
32
|
+
PARAMETER = /\s*;\s*(?<key>#{TOKEN})=((?<value>#{TOKEN})|(?<quoted_value>#{QUOTED_STRING}))/
|
33
|
+
|
34
|
+
class MediaRange < Struct.new(:mime_type, :parameters)
|
35
|
+
def quality_factor
|
36
|
+
parameters.fetch('q', 1.0).to_f
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.parse(scanner)
|
40
|
+
return to_enum(:parse, scanner) unless block_given?
|
41
|
+
|
42
|
+
while mime_type = scanner.scan(MIME_TYPE)
|
43
|
+
parameters = {}
|
44
|
+
|
45
|
+
while scanner.scan(PARAMETER)
|
46
|
+
key = scanner[:key]
|
47
|
+
|
48
|
+
if value = scanner[:value]
|
49
|
+
parameters[key] = value
|
50
|
+
elsif quoted_value = scanner[:quoted_value]
|
51
|
+
parameters[key] = QuotedString.new(quoted_value)
|
52
|
+
else
|
53
|
+
raise ParseError.new("Could not parse parameter!")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
yield self.new(mime_type, parameters)
|
58
|
+
|
59
|
+
# Are there more?
|
60
|
+
return unless scanner.scan(/\s*,\s*/)
|
61
|
+
end
|
62
|
+
|
63
|
+
raise ParseError.new("Could not parse entire string!") unless scanner.eos?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.parse(text)
|
68
|
+
scanner = StringScanner.new(text)
|
69
|
+
|
70
|
+
media_types = MediaRange.parse(scanner)
|
71
|
+
|
72
|
+
return Sort.by_quality_factor(media_types)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module HTTP
|
22
|
+
module Accept
|
23
|
+
class ParseError < ArgumentError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module HTTP
|
22
|
+
module Accept
|
23
|
+
# According to https://tools.ietf.org/html/rfc7231#appendix-C
|
24
|
+
TOKEN = /[!#$%&'*+\-.^_`|~0-9A-Z]+/i
|
25
|
+
QUOTED_STRING = /"(?:.(?!(?<!\\)"))*.?"/
|
26
|
+
|
27
|
+
class QuotedString
|
28
|
+
def initialize(value)
|
29
|
+
@value = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def unquote(normalize_whitespace = false)
|
33
|
+
value = @value[1...-1]
|
34
|
+
|
35
|
+
value.gsub!(/\\(.)/, '\1')
|
36
|
+
|
37
|
+
if normalize_whitespace
|
38
|
+
value = value.gsub!(/[\r\n](\s+)+/, ' ')
|
39
|
+
end
|
40
|
+
|
41
|
+
return value
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_str
|
45
|
+
unquote(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_s
|
49
|
+
to_str
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module HTTP
|
22
|
+
module Accept
|
23
|
+
module Sort
|
24
|
+
def self.by_quality_factor(items)
|
25
|
+
# We do this to get a stable sort:
|
26
|
+
items.sort_by.with_index{|object, index| [-object.quality_factor, index]}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module HTTP
|
22
|
+
module Accept
|
23
|
+
VERSION = "1.0.0"
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-accept
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- samuel.williams@oriontransfer.co.nz
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".simplecov"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- http-accept.gemspec
|
70
|
+
- lib/http/accept.rb
|
71
|
+
- lib/http/accept/languages.rb
|
72
|
+
- lib/http/accept/media_types.rb
|
73
|
+
- lib/http/accept/parse_error.rb
|
74
|
+
- lib/http/accept/quoted_string.rb
|
75
|
+
- lib/http/accept/sort.rb
|
76
|
+
- lib/http/accept/version.rb
|
77
|
+
homepage: https://github.com/ioquatix/http-accept
|
78
|
+
licenses: []
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.5.1
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Parse Accept and Accept-Language HTTP headers.
|
100
|
+
test_files: []
|