twitter_cldr 3.0.6 → 3.0.7
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 +5 -13
- data/Gemfile +1 -1
- data/History.txt +4 -0
- data/README.md +24 -1
- data/Rakefile +2 -0
- data/lib/twitter_cldr/localized/localized_string.rb +4 -0
- data/lib/twitter_cldr/resources/locales_resources_importer.rb +1 -1
- data/lib/twitter_cldr/shared/territories_containment.rb +81 -0
- data/lib/twitter_cldr/shared/territory.rb +31 -0
- data/lib/twitter_cldr/shared.rb +17 -15
- data/lib/twitter_cldr/version.rb +1 -1
- data/resources/shared/territories_containment.yml +415 -0
- data/spec/localized/localized_string_spec.rb +9 -0
- data/spec/shared/territories_containment_spec.rb +85 -0
- data/spec/shared/territory_spec.rb +41 -0
- metadata +15 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZjQxYmY5ZDE4NzE0OWQwNTIwYWUyNTc4ZWUyODgyOWY5YWE4NzA4Mw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e75bddb2f0b74556c03ba205bc1638a434ea485f
|
4
|
+
data.tar.gz: ce3078bb2a6a57f429c08e36900238be9e2ab4d8
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YTNkYmNiNjAzMDljMDQ0ZWFmZWNhZjYxNWUzYjg2Njg0YWI2YTU2Yjc4NmRh
|
11
|
-
MzE1YTQxYzMzNmEwMTY0ODc2YWIwYWMwMmQ4ZTk0MDQ5NGFmYTk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NTk3N2YxYzRiOGQ3YmE4OGY3ZGFhNWNmNjllNDE2YjhiMjE2ZjgzM2Q0MmQx
|
14
|
-
MzI4NWU5ZjUxMGQ1Nzc3Y2Q0ZTRhY2U2NzcyOTZjNzY1YjdhZWI4YzlkNjFl
|
15
|
-
Mzg2ZDE3YWI4ODhhMDczMGQ4NzQ3NjM0MWYzNTBhNWQwN2E4YmI=
|
6
|
+
metadata.gz: a61b73449810b306f3037505690f45cb19e36d23812006484f1ba201b2e401cc9ffc0956600fee0387ecc94981eef43688bfa104b1e9e3a743ffa1ab45c4a003
|
7
|
+
data.tar.gz: 858f231f21e46e8df9cd6d32ad194ba73474fca48c3e8f72889bc485d58569e8a617ba00a672370463bdad014cce8860f959c96bd850681aeb8868fe179dd7e5
|
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -472,7 +472,7 @@ postal_code.regexp # /\d{5}([ \-]\d{4})?/
|
|
472
472
|
Get a sample of valid postal codes with the `#sample` method:
|
473
473
|
|
474
474
|
```ruby
|
475
|
-
postal_code.sample(5) # ["
|
475
|
+
postal_code.sample(5) # ["93733-7601", "65796-6586", "93519", "46536", "53158"]
|
476
476
|
```
|
477
477
|
|
478
478
|
### Phone Codes
|
@@ -555,6 +555,29 @@ TwitterCldr::Shared::LanguageCodes.to_language(:spa, :iso_639_2) # "Spanish"
|
|
555
555
|
|
556
556
|
**NOTE**: All of the functions in `TwitterCldr::Shared::LanguageCodes` accept both symbol and string parameters.
|
557
557
|
|
558
|
+
### Territories Containment
|
559
|
+
|
560
|
+
Provides an API for determining territories containment as described [here](http://www.unicode.org/cldr/charts/25/supplemental/territory_containment_un_m_49.html):
|
561
|
+
|
562
|
+
```ruby
|
563
|
+
TwitterCldr::Shared::TerritoriesContainment.children('151') # ["BG", "BY", "CZ", "HU", "MD", "PL", "RO", "RU", "SK", "SU", "UA", ... ]
|
564
|
+
TwitterCldr::Shared::TerritoriesContainment.children('RU') # []
|
565
|
+
|
566
|
+
TwitterCldr::Shared::TerritoriesContainment.parents('013') # ["003", "019", "419"]
|
567
|
+
TwitterCldr::Shared::TerritoriesContainment.parents('001') # []
|
568
|
+
|
569
|
+
TwitterCldr::Shared::TerritoriesContainment.contains?('151', 'RU') # true
|
570
|
+
TwitterCldr::Shared::TerritoriesContainment.contains?('419', 'BZ') # true
|
571
|
+
TwitterCldr::Shared::TerritoriesContainment.contains?('419', 'FR') # false
|
572
|
+
```
|
573
|
+
|
574
|
+
You can also use `Territory` class and `to_territory` method in `LocalizedString` class to access these features:
|
575
|
+
|
576
|
+
```ruby
|
577
|
+
TwitterCldr::Shared::Territory.new("013").parents # ["003", "019", "419"]
|
578
|
+
'419'.localize.to_territory.contains?('BZ') # true
|
579
|
+
```
|
580
|
+
|
558
581
|
### Unicode Regular Expressions
|
559
582
|
|
560
583
|
Unicode regular expressions are an extension of the normal regular expression syntax. All of the changes are local to the regex's character class feature and provide support for multi-character strings, Unicode character escapes, set operations (unions, intersections, and differences), and character sets.
|
data/Rakefile
CHANGED
@@ -211,6 +211,7 @@ namespace :update do
|
|
211
211
|
).import(TwitterCldr.supported_locales)
|
212
212
|
end
|
213
213
|
|
214
|
+
desc 'Import segments exceptions'
|
214
215
|
task :segment_exceptions do
|
215
216
|
TwitterCldr::Resources::Uli::SegmentExceptionsImporter.new(
|
216
217
|
'./vendor/uli/segments',
|
@@ -218,6 +219,7 @@ namespace :update do
|
|
218
219
|
).import([:de, :en, :es, :fr, :it, :pt, :ru]) # only locales ULI supports at the moment
|
219
220
|
end
|
220
221
|
|
222
|
+
desc 'Update README'
|
221
223
|
task :readme do |_, args|
|
222
224
|
renderer = TwitterCldr::Resources::ReadmeRenderer.new(
|
223
225
|
File.read("./README.md.erb")
|
@@ -16,7 +16,7 @@ module TwitterCldr
|
|
16
16
|
# NOTE: units.yml was NOT updated to cldr 24 (too many significant changes) - add back in when appropriate.
|
17
17
|
# Meanwhile, use ruby-cldr v0.0.2 and CLDR 22.1 to update units.yml files.
|
18
18
|
LOCALE_COMPONENTS = %w[calendars languages numbers plurals lists layout currencies territories rbnf] # units
|
19
|
-
SHARED_COMPONENTS = %w[currency_digits_and_rounding rbnf_root numbering_systems segments_root]
|
19
|
+
SHARED_COMPONENTS = %w[currency_digits_and_rounding rbnf_root numbering_systems segments_root territories_containment]
|
20
20
|
|
21
21
|
# Arguments:
|
22
22
|
#
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
module TwitterCldr
|
7
|
+
module Shared
|
8
|
+
|
9
|
+
module TerritoriesContainment
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
# Returns true if the first territory contains the second one. Returns false otherwise.
|
14
|
+
# Raises an ArgumentError exception if one of the territories is invalid.
|
15
|
+
def contains?(parent_code, child_code)
|
16
|
+
validate_territory(parent_code)
|
17
|
+
validate_territory(child_code)
|
18
|
+
|
19
|
+
immediate_children = children(parent_code)
|
20
|
+
|
21
|
+
immediate_children.include?(child_code) ||
|
22
|
+
immediate_children.any? { |immediate_child| contains?(immediate_child, child_code) }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the immediate parent of the territory with the given code.
|
26
|
+
# Raises an ArgumentError exception if the territory code is invalid.
|
27
|
+
def parents(territory_code)
|
28
|
+
validate_territory(territory_code)
|
29
|
+
|
30
|
+
parents_map[territory_code]
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the immediate parent of the territory with the given code.
|
34
|
+
# Raises an ArgumentError exception if the territory code is invalid.
|
35
|
+
def children(territory_code)
|
36
|
+
validate_territory(territory_code)
|
37
|
+
|
38
|
+
containment_map[territory_code]
|
39
|
+
end
|
40
|
+
|
41
|
+
def containment_map
|
42
|
+
@containment_map ||= get_resource.inject(Hash.new { |h, k| h[k] = [] }) do |memo, (territory, children)|
|
43
|
+
memo[territory.to_s] = children[:contains].map(&:to_s)
|
44
|
+
memo
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def validate_territory(territory_code)
|
51
|
+
raise unknown_territory_exception(territory_code) unless parents_map.include?(territory_code)
|
52
|
+
end
|
53
|
+
|
54
|
+
def unknown_territory_exception(territory_code)
|
55
|
+
ArgumentError.new("unknown territory code #{territory_code.inspect}")
|
56
|
+
end
|
57
|
+
|
58
|
+
def parents_map
|
59
|
+
@parents_map ||= containment_map.inject({}) do |memo, (territory, children)|
|
60
|
+
# make sure that the top-level territories are explicitly present in the map (with [] as their parent)
|
61
|
+
memo[territory] = [] unless memo.include?(territory)
|
62
|
+
|
63
|
+
children.each do |child|
|
64
|
+
memo[child] = [] unless memo.include?(child)
|
65
|
+
memo[child] << territory # do not override
|
66
|
+
end
|
67
|
+
|
68
|
+
memo
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_resource
|
73
|
+
TwitterCldr.get_resource(:shared, :territories_containment)[:territories]
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
module TwitterCldr
|
7
|
+
module Shared
|
8
|
+
|
9
|
+
class Territory
|
10
|
+
attr_reader :code
|
11
|
+
|
12
|
+
def initialize(territory_code)
|
13
|
+
@code = territory_code
|
14
|
+
end
|
15
|
+
|
16
|
+
def contains?(territory_code)
|
17
|
+
TerritoriesContainment.contains?(code, territory_code)
|
18
|
+
end
|
19
|
+
|
20
|
+
def parents
|
21
|
+
TerritoriesContainment.parents(code)
|
22
|
+
end
|
23
|
+
|
24
|
+
def children
|
25
|
+
TerritoriesContainment.children(code)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/lib/twitter_cldr/shared.rb
CHANGED
@@ -5,20 +5,22 @@
|
|
5
5
|
|
6
6
|
module TwitterCldr
|
7
7
|
module Shared
|
8
|
-
autoload :
|
9
|
-
autoload :
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
autoload :
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
20
|
-
autoload :
|
21
|
-
autoload :
|
22
|
-
autoload :
|
8
|
+
autoload :Bidi, 'twitter_cldr/shared/bidi'
|
9
|
+
autoload :BreakIterator, 'twitter_cldr/shared/break_iterator'
|
10
|
+
autoload :Calendar, 'twitter_cldr/shared/calendar'
|
11
|
+
autoload :Casefolder, 'twitter_cldr/shared/casefolder'
|
12
|
+
autoload :CodePoint, 'twitter_cldr/shared/code_point'
|
13
|
+
autoload :Currencies, 'twitter_cldr/shared/currencies'
|
14
|
+
autoload :LanguageCodes, 'twitter_cldr/shared/language_codes'
|
15
|
+
autoload :Languages, 'twitter_cldr/shared/languages'
|
16
|
+
autoload :NumberingSystem, 'twitter_cldr/shared/numbering_system'
|
17
|
+
autoload :Numbers, 'twitter_cldr/shared/numbers'
|
18
|
+
autoload :PhoneCodes, 'twitter_cldr/shared/phone_codes'
|
19
|
+
autoload :PostalCodeGenerator, 'twitter_cldr/shared/postal_code_generator'
|
20
|
+
autoload :PostalCodes, 'twitter_cldr/shared/postal_codes'
|
21
|
+
autoload :Territories, 'twitter_cldr/shared/territories'
|
22
|
+
autoload :TerritoriesContainment, 'twitter_cldr/shared/territories_containment'
|
23
|
+
autoload :Territory, 'twitter_cldr/shared/territory'
|
24
|
+
autoload :UnicodeRegex, 'twitter_cldr/shared/unicode_regex'
|
23
25
|
end
|
24
26
|
end
|
data/lib/twitter_cldr/version.rb
CHANGED
@@ -0,0 +1,415 @@
|
|
1
|
+
---
|
2
|
+
:territories:
|
3
|
+
? !ruby/symbol "001"
|
4
|
+
:
|
5
|
+
:contains:
|
6
|
+
- "002"
|
7
|
+
- "009"
|
8
|
+
- "019"
|
9
|
+
- 142
|
10
|
+
- 150
|
11
|
+
? !ruby/symbol "002"
|
12
|
+
:
|
13
|
+
:contains:
|
14
|
+
- "011"
|
15
|
+
- "014"
|
16
|
+
- "015"
|
17
|
+
- "017"
|
18
|
+
- "018"
|
19
|
+
? !ruby/symbol "003"
|
20
|
+
:
|
21
|
+
:contains:
|
22
|
+
- "013"
|
23
|
+
- "021"
|
24
|
+
- "029"
|
25
|
+
? !ruby/symbol "005"
|
26
|
+
:
|
27
|
+
:contains:
|
28
|
+
- "AR"
|
29
|
+
- "BO"
|
30
|
+
- "BR"
|
31
|
+
- "CL"
|
32
|
+
- "CO"
|
33
|
+
- "EC"
|
34
|
+
- "FK"
|
35
|
+
- "GF"
|
36
|
+
- "GY"
|
37
|
+
- "PE"
|
38
|
+
- "PY"
|
39
|
+
- "SR"
|
40
|
+
- "UY"
|
41
|
+
- "VE"
|
42
|
+
:009:
|
43
|
+
:contains:
|
44
|
+
- "053"
|
45
|
+
- "054"
|
46
|
+
- "057"
|
47
|
+
- "061"
|
48
|
+
- "QO"
|
49
|
+
? !ruby/symbol "011"
|
50
|
+
:
|
51
|
+
:contains:
|
52
|
+
- "BF"
|
53
|
+
- "BJ"
|
54
|
+
- "CI"
|
55
|
+
- "CV"
|
56
|
+
- "GH"
|
57
|
+
- "GM"
|
58
|
+
- "GN"
|
59
|
+
- "GW"
|
60
|
+
- "LR"
|
61
|
+
- "ML"
|
62
|
+
- "MR"
|
63
|
+
- "NE"
|
64
|
+
- "NG"
|
65
|
+
- "SH"
|
66
|
+
- "SL"
|
67
|
+
- "SN"
|
68
|
+
- "TG"
|
69
|
+
? !ruby/symbol "013"
|
70
|
+
:
|
71
|
+
:contains:
|
72
|
+
- "BZ"
|
73
|
+
- "CR"
|
74
|
+
- "GT"
|
75
|
+
- "HN"
|
76
|
+
- "MX"
|
77
|
+
- "NI"
|
78
|
+
- "PA"
|
79
|
+
- "SV"
|
80
|
+
? !ruby/symbol "014"
|
81
|
+
:
|
82
|
+
:contains:
|
83
|
+
- "BI"
|
84
|
+
- "DJ"
|
85
|
+
- "ER"
|
86
|
+
- "ET"
|
87
|
+
- "KE"
|
88
|
+
- "KM"
|
89
|
+
- "MG"
|
90
|
+
- "MU"
|
91
|
+
- "MW"
|
92
|
+
- "MZ"
|
93
|
+
- "RE"
|
94
|
+
- "RW"
|
95
|
+
- "SC"
|
96
|
+
- "SO"
|
97
|
+
- "TZ"
|
98
|
+
- "UG"
|
99
|
+
- "YT"
|
100
|
+
- "ZM"
|
101
|
+
- "ZW"
|
102
|
+
? !ruby/symbol "015"
|
103
|
+
:
|
104
|
+
:contains:
|
105
|
+
- "DZ"
|
106
|
+
- "EA"
|
107
|
+
- "EG"
|
108
|
+
- "EH"
|
109
|
+
- "IC"
|
110
|
+
- "LY"
|
111
|
+
- "MA"
|
112
|
+
- "SD"
|
113
|
+
- "SS"
|
114
|
+
- "TN"
|
115
|
+
? !ruby/symbol "017"
|
116
|
+
:
|
117
|
+
:contains:
|
118
|
+
- "AO"
|
119
|
+
- "CD"
|
120
|
+
- "CF"
|
121
|
+
- "CG"
|
122
|
+
- "CM"
|
123
|
+
- "GA"
|
124
|
+
- "GQ"
|
125
|
+
- "ST"
|
126
|
+
- "TD"
|
127
|
+
- "ZR"
|
128
|
+
:018:
|
129
|
+
:contains:
|
130
|
+
- "BW"
|
131
|
+
- "LS"
|
132
|
+
- "NA"
|
133
|
+
- "SZ"
|
134
|
+
- "ZA"
|
135
|
+
:019:
|
136
|
+
:contains:
|
137
|
+
- "003"
|
138
|
+
- "005"
|
139
|
+
- "013"
|
140
|
+
- "021"
|
141
|
+
- "029"
|
142
|
+
- 419
|
143
|
+
? !ruby/symbol "021"
|
144
|
+
:
|
145
|
+
:contains:
|
146
|
+
- "BM"
|
147
|
+
- "CA"
|
148
|
+
- "GL"
|
149
|
+
- "PM"
|
150
|
+
- "US"
|
151
|
+
:029:
|
152
|
+
:contains:
|
153
|
+
- "AG"
|
154
|
+
- "AI"
|
155
|
+
- "AN"
|
156
|
+
- "AW"
|
157
|
+
- "BB"
|
158
|
+
- "BL"
|
159
|
+
- "BQ"
|
160
|
+
- "BS"
|
161
|
+
- "CU"
|
162
|
+
- "CW"
|
163
|
+
- "DM"
|
164
|
+
- "DO"
|
165
|
+
- "GD"
|
166
|
+
- "GP"
|
167
|
+
- "HT"
|
168
|
+
- "JM"
|
169
|
+
- "KN"
|
170
|
+
- "KY"
|
171
|
+
- "LC"
|
172
|
+
- "MF"
|
173
|
+
- "MQ"
|
174
|
+
- "MS"
|
175
|
+
- "PR"
|
176
|
+
- "SX"
|
177
|
+
- "TC"
|
178
|
+
- "TT"
|
179
|
+
- "VC"
|
180
|
+
- "VG"
|
181
|
+
- "VI"
|
182
|
+
? !ruby/symbol "030"
|
183
|
+
:
|
184
|
+
:contains:
|
185
|
+
- "CN"
|
186
|
+
- "HK"
|
187
|
+
- "JP"
|
188
|
+
- "KP"
|
189
|
+
- "KR"
|
190
|
+
- "MN"
|
191
|
+
- "MO"
|
192
|
+
- "TW"
|
193
|
+
? !ruby/symbol "034"
|
194
|
+
:
|
195
|
+
:contains:
|
196
|
+
- "AF"
|
197
|
+
- "BD"
|
198
|
+
- "BT"
|
199
|
+
- "IN"
|
200
|
+
- "IR"
|
201
|
+
- "LK"
|
202
|
+
- "MV"
|
203
|
+
- "NP"
|
204
|
+
- "PK"
|
205
|
+
? !ruby/symbol "035"
|
206
|
+
:
|
207
|
+
:contains:
|
208
|
+
- "BN"
|
209
|
+
- "BU"
|
210
|
+
- "ID"
|
211
|
+
- "KH"
|
212
|
+
- "LA"
|
213
|
+
- "MM"
|
214
|
+
- "MY"
|
215
|
+
- "PH"
|
216
|
+
- "SG"
|
217
|
+
- "TH"
|
218
|
+
- "TL"
|
219
|
+
- "TP"
|
220
|
+
- "VN"
|
221
|
+
:039:
|
222
|
+
:contains:
|
223
|
+
- "AD"
|
224
|
+
- "AL"
|
225
|
+
- "BA"
|
226
|
+
- "CS"
|
227
|
+
- "ES"
|
228
|
+
- "GI"
|
229
|
+
- "GR"
|
230
|
+
- "HR"
|
231
|
+
- "IT"
|
232
|
+
- "ME"
|
233
|
+
- "MK"
|
234
|
+
- "MT"
|
235
|
+
- "PT"
|
236
|
+
- "RS"
|
237
|
+
- "SI"
|
238
|
+
- "SM"
|
239
|
+
- "VA"
|
240
|
+
- "XK"
|
241
|
+
- "YU"
|
242
|
+
? !ruby/symbol "053"
|
243
|
+
:
|
244
|
+
:contains:
|
245
|
+
- "AU"
|
246
|
+
- "NF"
|
247
|
+
- "NZ"
|
248
|
+
? !ruby/symbol "054"
|
249
|
+
:
|
250
|
+
:contains:
|
251
|
+
- "FJ"
|
252
|
+
- "NC"
|
253
|
+
- "PG"
|
254
|
+
- "SB"
|
255
|
+
- "VU"
|
256
|
+
? !ruby/symbol "057"
|
257
|
+
:
|
258
|
+
:contains:
|
259
|
+
- "FM"
|
260
|
+
- "GU"
|
261
|
+
- "KI"
|
262
|
+
- "MH"
|
263
|
+
- "MP"
|
264
|
+
- "NR"
|
265
|
+
- "PW"
|
266
|
+
? !ruby/symbol "061"
|
267
|
+
:
|
268
|
+
:contains:
|
269
|
+
- "AS"
|
270
|
+
- "CK"
|
271
|
+
- "NU"
|
272
|
+
- "PF"
|
273
|
+
- "PN"
|
274
|
+
- "TK"
|
275
|
+
- "TO"
|
276
|
+
- "TV"
|
277
|
+
- "WF"
|
278
|
+
- "WS"
|
279
|
+
142:
|
280
|
+
:contains:
|
281
|
+
- "030"
|
282
|
+
- "034"
|
283
|
+
- "035"
|
284
|
+
- 143
|
285
|
+
- 145
|
286
|
+
143:
|
287
|
+
:contains:
|
288
|
+
- "KG"
|
289
|
+
- "KZ"
|
290
|
+
- "TJ"
|
291
|
+
- "TM"
|
292
|
+
- "UZ"
|
293
|
+
145:
|
294
|
+
:contains:
|
295
|
+
- "AE"
|
296
|
+
- "AM"
|
297
|
+
- "AZ"
|
298
|
+
- "BH"
|
299
|
+
- "CY"
|
300
|
+
- "GE"
|
301
|
+
- "IL"
|
302
|
+
- "IQ"
|
303
|
+
- "JO"
|
304
|
+
- "KW"
|
305
|
+
- "LB"
|
306
|
+
- "NT"
|
307
|
+
- "OM"
|
308
|
+
- "PS"
|
309
|
+
- "QA"
|
310
|
+
- "SA"
|
311
|
+
- "SY"
|
312
|
+
- "TR"
|
313
|
+
- "YD"
|
314
|
+
- "YE"
|
315
|
+
150:
|
316
|
+
:contains:
|
317
|
+
- "039"
|
318
|
+
- 151
|
319
|
+
- 154
|
320
|
+
- 155
|
321
|
+
- "EU"
|
322
|
+
- "QU"
|
323
|
+
151:
|
324
|
+
:contains:
|
325
|
+
- "BG"
|
326
|
+
- "BY"
|
327
|
+
- "CZ"
|
328
|
+
- "HU"
|
329
|
+
- "MD"
|
330
|
+
- "PL"
|
331
|
+
- "RO"
|
332
|
+
- "RU"
|
333
|
+
- "SK"
|
334
|
+
- "SU"
|
335
|
+
- "UA"
|
336
|
+
154:
|
337
|
+
:contains:
|
338
|
+
- "AX"
|
339
|
+
- "DK"
|
340
|
+
- "EE"
|
341
|
+
- "FI"
|
342
|
+
- "FO"
|
343
|
+
- "GB"
|
344
|
+
- "GG"
|
345
|
+
- "IE"
|
346
|
+
- "IM"
|
347
|
+
- "IS"
|
348
|
+
- "JE"
|
349
|
+
- "LT"
|
350
|
+
- "LV"
|
351
|
+
- false
|
352
|
+
- "SE"
|
353
|
+
- "SJ"
|
354
|
+
155:
|
355
|
+
:contains:
|
356
|
+
- "AT"
|
357
|
+
- "BE"
|
358
|
+
- "CH"
|
359
|
+
- "DD"
|
360
|
+
- "DE"
|
361
|
+
- "FR"
|
362
|
+
- "FX"
|
363
|
+
- "LI"
|
364
|
+
- "LU"
|
365
|
+
- "MC"
|
366
|
+
- "NL"
|
367
|
+
419:
|
368
|
+
:contains:
|
369
|
+
- "005"
|
370
|
+
- "013"
|
371
|
+
- "029"
|
372
|
+
:EU:
|
373
|
+
:contains:
|
374
|
+
- "AT"
|
375
|
+
- "BE"
|
376
|
+
- "BG"
|
377
|
+
- "CY"
|
378
|
+
- "CZ"
|
379
|
+
- "DE"
|
380
|
+
- "DK"
|
381
|
+
- "EE"
|
382
|
+
- "ES"
|
383
|
+
- "FI"
|
384
|
+
- "FR"
|
385
|
+
- "GB"
|
386
|
+
- "GR"
|
387
|
+
- "HU"
|
388
|
+
- "IE"
|
389
|
+
- "IT"
|
390
|
+
- "LT"
|
391
|
+
- "LU"
|
392
|
+
- "LV"
|
393
|
+
- "MT"
|
394
|
+
- "NL"
|
395
|
+
- "PL"
|
396
|
+
- "PT"
|
397
|
+
- "RO"
|
398
|
+
- "SE"
|
399
|
+
- "SI"
|
400
|
+
- "SK"
|
401
|
+
:QO:
|
402
|
+
:contains:
|
403
|
+
- "AC"
|
404
|
+
- "AQ"
|
405
|
+
- "BV"
|
406
|
+
- "CC"
|
407
|
+
- "CP"
|
408
|
+
- "CX"
|
409
|
+
- "DG"
|
410
|
+
- "GS"
|
411
|
+
- "HM"
|
412
|
+
- "IO"
|
413
|
+
- "TA"
|
414
|
+
- "TF"
|
415
|
+
- "UM"
|
@@ -242,4 +242,13 @@ describe LocalizedString do
|
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
|
+
describe '#to_territory' do
|
246
|
+
let(:code) { 'JP' }
|
247
|
+
let(:territory) { code.localize.to_territory }
|
248
|
+
|
249
|
+
it 'returns a territory' do
|
250
|
+
expect(territory).to be_a(TwitterCldr::Shared::Territory)
|
251
|
+
expect(territory.code).to eq(code)
|
252
|
+
end
|
253
|
+
end
|
245
254
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
include TwitterCldr::Shared
|
9
|
+
|
10
|
+
describe TerritoriesContainment do
|
11
|
+
describe '.parents' do
|
12
|
+
it 'returns the parent territory' do
|
13
|
+
expect(TerritoriesContainment.parents('RU')).to eq(['151'])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns multiple parents' do
|
17
|
+
expect(TerritoriesContainment.parents('013')).to match_array(%w[003 019 419])
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns [] when given a top-level territory' do
|
21
|
+
expect(TerritoriesContainment.parents('001')).to eq([])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raises an exception when given an invalid territory code' do
|
25
|
+
expect { TerritoriesContainment.parents('UN') }.to raise_exception(ArgumentError, 'unknown territory code "UN"')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.children' do
|
30
|
+
it 'returns the immediate children of the territory' do
|
31
|
+
expect(TerritoriesContainment.children('151')).to eq(%w[BG BY CZ HU MD PL RO RU SK SU UA])
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns codes with leading zeros' do
|
35
|
+
expect(TerritoriesContainment.children('009')).to eq(%w[053 054 057 061 QO])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns an empty array when given a bottom-level territory' do
|
39
|
+
expect(TerritoriesContainment.children('RU')).to eq([])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'raises an exception when given an invalid territory code' do
|
43
|
+
expect { TerritoriesContainment.children('UN') }.to raise_exception(ArgumentError, 'unknown territory code "UN"')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.contains?' do
|
48
|
+
it 'returns true if the first territory (immediately) contains the second one' do
|
49
|
+
expect(TerritoriesContainment.contains?('151', 'RU')).to be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns true if the first territory (non-immediately) contains the second one' do
|
53
|
+
expect(TerritoriesContainment.contains?('419', 'BZ')).to be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns true if a territory is part of multiple parent territories' do
|
57
|
+
expect(TerritoriesContainment.contains?('019', '013')).to be_true
|
58
|
+
expect(TerritoriesContainment.contains?('419', '013')).to be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns true if the first territory is a top-level territory' do
|
62
|
+
expect(TerritoriesContainment.contains?('001', '145')).to be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns false if the first territory does not contain the second one' do
|
66
|
+
expect(TerritoriesContainment.contains?('419', 'RU')).to be_false
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns false if the second territory is a top-level territory' do
|
70
|
+
expect(TerritoriesContainment.contains?('419', '001')).to be_false
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns false if both territories are identical' do
|
74
|
+
expect(TerritoriesContainment.contains?('RU', 'RU')).to be_false
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'raises an exception is the first territory is invalid' do
|
78
|
+
expect { TerritoriesContainment.contains?('UN', 'RU') }.to raise_exception(ArgumentError, 'unknown territory code "UN"')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'raises an exception is the second territory is invalid' do
|
82
|
+
expect { TerritoriesContainment.contains?('RU', 'UN') }.to raise_exception(ArgumentError, 'unknown territory code "UN"')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
include TwitterCldr::Shared
|
9
|
+
|
10
|
+
describe Territory do
|
11
|
+
let(:code) { '013' }
|
12
|
+
let(:territory) { Territory.new(code) }
|
13
|
+
|
14
|
+
describe '#parents' do
|
15
|
+
let(:parents) { %w[013 territory parents] }
|
16
|
+
|
17
|
+
it 'delegates to TerritoriesContainment.parents' do
|
18
|
+
mock(TerritoriesContainment).parents(code) { parents }
|
19
|
+
expect(territory.parents).to eq(parents)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#children' do
|
24
|
+
let(:children) { %w[013 territory children] }
|
25
|
+
|
26
|
+
it 'delegates to TerritoriesContainment.children' do
|
27
|
+
mock(TerritoriesContainment).children(code) { children }
|
28
|
+
expect(territory.children).to eq(children)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#contains?' do
|
33
|
+
let(:other_code) { 'RU' }
|
34
|
+
let(:result) { 'containment result' }
|
35
|
+
|
36
|
+
it 'delegates to TerritoriesContainment.contains?' do
|
37
|
+
mock(TerritoriesContainment).contains?(code, other_code) { result }
|
38
|
+
expect(territory.contains?(other_code)).to be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_cldr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: camertron-eprun
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: tzinfo
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Ruby implementation of the ICU (International Components for Unicode)
|
@@ -176,6 +176,8 @@ files:
|
|
176
176
|
- lib/twitter_cldr/shared/postal_code_generator.rb
|
177
177
|
- lib/twitter_cldr/shared/postal_codes.rb
|
178
178
|
- lib/twitter_cldr/shared/territories.rb
|
179
|
+
- lib/twitter_cldr/shared/territories_containment.rb
|
180
|
+
- lib/twitter_cldr/shared/territory.rb
|
179
181
|
- lib/twitter_cldr/shared/timezones.rb
|
180
182
|
- lib/twitter_cldr/shared/unicode_regex.rb
|
181
183
|
- lib/twitter_cldr/tokenizers.rb
|
@@ -1040,6 +1042,7 @@ files:
|
|
1040
1042
|
- resources/shared/rbnf_root.yml
|
1041
1043
|
- resources/shared/segments/segments_root.yml
|
1042
1044
|
- resources/shared/segments/tailorings/en.yml
|
1045
|
+
- resources/shared/territories_containment.yml
|
1043
1046
|
- resources/uli/segments/de.yml
|
1044
1047
|
- resources/uli/segments/en.yml
|
1045
1048
|
- resources/uli/segments/es.yml
|
@@ -1452,7 +1455,9 @@ files:
|
|
1452
1455
|
- spec/shared/phone_codes_spec.rb
|
1453
1456
|
- spec/shared/postal_code_generator_spec.rb
|
1454
1457
|
- spec/shared/postal_codes_spec.rb
|
1458
|
+
- spec/shared/territories_containment_spec.rb
|
1455
1459
|
- spec/shared/territories_spec.rb
|
1460
|
+
- spec/shared/territory_spec.rb
|
1456
1461
|
- spec/shared/unicode_regex_spec.rb
|
1457
1462
|
- spec/spec_helper.rb
|
1458
1463
|
- spec/tokenizers/calendars/date_tokenizer_spec.rb
|
@@ -1484,12 +1489,12 @@ require_paths:
|
|
1484
1489
|
- lib
|
1485
1490
|
required_ruby_version: !ruby/object:Gem::Requirement
|
1486
1491
|
requirements:
|
1487
|
-
- -
|
1492
|
+
- - '>='
|
1488
1493
|
- !ruby/object:Gem::Version
|
1489
1494
|
version: '0'
|
1490
1495
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
1491
1496
|
requirements:
|
1492
|
-
- -
|
1497
|
+
- - '>='
|
1493
1498
|
- !ruby/object:Gem::Version
|
1494
1499
|
version: '0'
|
1495
1500
|
requirements: []
|