http_headers-accept_language 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +78 -71
- data/http_headers-accept_language.gemspec +1 -1
- data/lib/http_headers/accept_language.rb +2 -4
- data/lib/http_headers/accept_language/version.rb +7 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ebbfe93a601fdf946138124adc1470197707f10cf77c9c8795e514a3a52f7a1
|
4
|
+
data.tar.gz: a3c87d59b5a95e28da456ebf26b1195a453aadfb8e825ad8f6b50a82c4bf271b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26d0e5986b8db74aeff6bb59a1331d7df5876519454fc381fcd856eecd0a2f980f73c5344ed87d98fa781c5d440ccdced1bb96072aaeda4ea8933500c53503d8
|
7
|
+
data.tar.gz: bcef004d6d4e73af6690f4f9aa18460da9a8a77aa17cc37c4d15b01b0cfa6d203d6225db895c0b81fb58ad3e2cf42ddcd230d6d6e12fd9398396974f7e29c261
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,71 +1,78 @@
|
|
1
|
-
# HttpHeaders::AcceptLanguage
|
2
|
-
|
3
|
-
[](https://travis-ci.com/XPBytes/http_headers-accept)
|
4
|
-
[](https://badge.fury.io/rb/http_headers-accept)
|
5
|
-
[](http://opensource.org/licenses/MIT)
|
6
|
-
|
7
|
-
:nut_and_bolt: Utility to parse and sort the "Accept-Language" HTTP Header
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Add this line to your application's Gemfile:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem 'http_headers-accept_language'
|
15
|
-
```
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install http_headers-accept_language
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
You can parse the "Accept-Language" header. As per the RFCs, you should really have one (delimited) value but the current
|
28
|
-
implementation accepts an array of values.
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
require 'http_headers/accept_language'
|
32
|
-
|
33
|
-
parsed = HttpHeaders::AcceptLanguage.new('nl-NL, nl, en-US; q=0.4, en; q=0.1')
|
34
|
-
parsed.first.region
|
35
|
-
# => 'NL'
|
36
|
-
parsed.last.q
|
37
|
-
# => 0.1
|
38
|
-
|
39
|
-
|
40
|
-
parsed = HttpHeaders::AcceptLanguage.new([
|
41
|
-
'eo; q=0.1',
|
42
|
-
'es-ES; foo=bar, es-MX; q=0.9'
|
43
|
-
])
|
44
|
-
parsed.first[:foo]
|
45
|
-
# => bar
|
46
|
-
parsed.last.to_s
|
47
|
-
# => 'eo; q=0.1'
|
48
|
-
parsed[1].locale
|
49
|
-
# => 'es-MX'
|
50
|
-
```
|
51
|
-
|
52
|
-
Each parsed entry has the following methods:
|
53
|
-
- `locale`: the parsed locale
|
54
|
-
- `language`: the language part of the `locale`
|
55
|
-
- `region`: the region part of the `locale`
|
56
|
-
- `q`: the quality parameter as float, or 1.0
|
57
|
-
- `[](parameter)`: accessor for the parameter; throws if it does not exist
|
58
|
-
- `to_s`: encode back to an entry to be used in a `Accept-Language` header
|
59
|
-
|
60
|
-
##
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
1
|
+
# HttpHeaders::AcceptLanguage
|
2
|
+
|
3
|
+
[](https://travis-ci.com/XPBytes/http_headers-accept)
|
4
|
+
[](https://badge.fury.io/rb/http_headers-accept)
|
5
|
+
[](http://opensource.org/licenses/MIT)
|
6
|
+
|
7
|
+
:nut_and_bolt: Utility to parse and sort the "Accept-Language" HTTP Header
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'http_headers-accept_language'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install http_headers-accept_language
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
You can parse the "Accept-Language" header. As per the RFCs, you should really have one (delimited) value but the current
|
28
|
+
implementation accepts an array of values.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'http_headers/accept_language'
|
32
|
+
|
33
|
+
parsed = HttpHeaders::AcceptLanguage.new('nl-NL, nl, en-US; q=0.4, en; q=0.1')
|
34
|
+
parsed.first.region
|
35
|
+
# => 'NL'
|
36
|
+
parsed.last.q
|
37
|
+
# => 0.1
|
38
|
+
|
39
|
+
|
40
|
+
parsed = HttpHeaders::AcceptLanguage.new([
|
41
|
+
'eo; q=0.1',
|
42
|
+
'es-ES; foo=bar, es-MX; q=0.9'
|
43
|
+
])
|
44
|
+
parsed.first[:foo]
|
45
|
+
# => bar
|
46
|
+
parsed.last.to_s
|
47
|
+
# => 'eo; q=0.1'
|
48
|
+
parsed[1].locale
|
49
|
+
# => 'es-MX'
|
50
|
+
```
|
51
|
+
|
52
|
+
Each parsed entry has the following methods:
|
53
|
+
- `locale`: the parsed locale
|
54
|
+
- `language`: the language part of the `locale`
|
55
|
+
- `region`: the region part of the `locale`
|
56
|
+
- `q`: the quality parameter as float, or 1.0
|
57
|
+
- `[](parameter)`: accessor for the parameter; throws if it does not exist
|
58
|
+
- `to_s`: encode back to an entry to be used in a `Accept-Language` header
|
59
|
+
|
60
|
+
## Related
|
61
|
+
|
62
|
+
- [HttpHeaders::Utils](https://github.com/XPBytes/http_headers-utils): :nut_and_bolt: Utility belt for the HttpHeader libraries
|
63
|
+
- [HttpHeaders::Accept](https://github.com/XPBytes/http_headers-accept): :nut_and_bolt: Utility to parse and sort the "Accept" HTTP Header
|
64
|
+
- [HttpHeaders::ContentType](https://github.com/XPBytes/http_headers-content_type): :nut_and_bolt: Utility to parse and sort the "Content-Type" HTTP Header
|
65
|
+
- [HttpHeaders::Link](https://github.com/XPBytes/http_headers-link): :nut_and_bolt: Utility to parse and sort the "Link" HTTP Header
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
70
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
71
|
+
|
72
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
73
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
74
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at [XPBytes/http_headers-accept](https://github.com/XPBytes/http_headers-accept).
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "http_headers/accept_language"
|
4
|
+
require "http_headers/accept_language/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "http_headers-accept_language"
|
@@ -1,10 +1,8 @@
|
|
1
|
+
require 'http_headers/accept_language/version'
|
1
2
|
require 'http_headers/utils'
|
2
|
-
require 'delegate'
|
3
3
|
|
4
4
|
module HttpHeaders
|
5
|
-
class AcceptLanguage < DelegateClass(Array)
|
6
|
-
VERSION = '0.2.0'
|
7
|
-
|
5
|
+
class AcceptLanguage # < DelegateClass(Array) determined by version
|
8
6
|
def initialize(value)
|
9
7
|
__setobj__ HttpHeaders::Utils::List.new(value, entry_klazz: Entry)
|
10
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_headers-accept_language
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- http_headers-accept_language.gemspec
|
101
101
|
- lib/http_headers/accept_language.rb
|
102
|
+
- lib/http_headers/accept_language/version.rb
|
102
103
|
homepage: https://github.com/XPBytes/http_headers-accept_language
|
103
104
|
licenses:
|
104
105
|
- MIT
|