iso 0.1.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -4
- data/Gemfile.lock +122 -47
- data/README.md +13 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/data/iso-3166-1.yml +1 -0
- data/data/iso-639-1.yml +3 -1
- data/data/un-m49.yml +503 -0
- data/iso.gemspec +39 -34
- data/lib/iso.rb +5 -4
- data/lib/iso/region.rb +2 -1
- data/lib/iso/subtag.rb +4 -1
- data/lib/iso/tag.rb +1 -1
- data/lib/iso/un/region.rb +23 -0
- data/locales/en.yml +37 -0
- data/locales/fr.yml +1 -0
- data/spec/lib/iso/language_spec.rb +10 -10
- data/spec/lib/iso/region_spec.rb +6 -6
- data/spec/lib/iso/subtag_spec.rb +28 -12
- data/spec/lib/iso/tag_spec.rb +39 -22
- data/spec/lib/iso/un/region_spec.rb +38 -0
- data/spec/spec_helper.rb +1 -0
- metadata +67 -47
data/iso.gemspec
CHANGED
@@ -2,16 +2,18 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: iso 0.4.0 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
8
|
+
s.name = "iso".freeze
|
9
|
+
s.version = "0.4.0"
|
9
10
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Christopher Dell".freeze, "Thibault Dalban".freeze]
|
14
|
+
s.date = "2020-11-17"
|
15
|
+
s.description = "A subset of the ISO spec implemented in ruby".freeze
|
16
|
+
s.email = "chris@tigrish.com".freeze
|
15
17
|
s.extra_rdoc_files = [
|
16
18
|
"LICENSE.txt",
|
17
19
|
"README.md"
|
@@ -19,6 +21,7 @@ Gem::Specification.new do |s|
|
|
19
21
|
s.files = [
|
20
22
|
".document",
|
21
23
|
".rspec",
|
24
|
+
".travis.yml",
|
22
25
|
"Gemfile",
|
23
26
|
"Gemfile.lock",
|
24
27
|
"Guardfile",
|
@@ -28,12 +31,14 @@ Gem::Specification.new do |s|
|
|
28
31
|
"VERSION",
|
29
32
|
"data/iso-3166-1.yml",
|
30
33
|
"data/iso-639-1.yml",
|
34
|
+
"data/un-m49.yml",
|
31
35
|
"iso.gemspec",
|
32
36
|
"lib/iso.rb",
|
33
37
|
"lib/iso/language.rb",
|
34
38
|
"lib/iso/region.rb",
|
35
39
|
"lib/iso/subtag.rb",
|
36
40
|
"lib/iso/tag.rb",
|
41
|
+
"lib/iso/un/region.rb",
|
37
42
|
"locales/en.yml",
|
38
43
|
"locales/fr.yml",
|
39
44
|
"spec/fixtures/base.yml",
|
@@ -41,42 +46,42 @@ Gem::Specification.new do |s|
|
|
41
46
|
"spec/lib/iso/region_spec.rb",
|
42
47
|
"spec/lib/iso/subtag_spec.rb",
|
43
48
|
"spec/lib/iso/tag_spec.rb",
|
49
|
+
"spec/lib/iso/un/region_spec.rb",
|
44
50
|
"spec/spec_helper.rb"
|
45
51
|
]
|
46
|
-
s.homepage =
|
47
|
-
s.licenses = [
|
48
|
-
s.
|
49
|
-
s.
|
50
|
-
s.summary = %q{A ruby implementation of ISO}
|
52
|
+
s.homepage = "http://github.com/tigrish/iso".freeze
|
53
|
+
s.licenses = ["MIT".freeze]
|
54
|
+
s.rubygems_version = "3.0.3".freeze
|
55
|
+
s.summary = "A ruby implementation of ISO".freeze
|
51
56
|
|
52
57
|
if s.respond_to? :specification_version then
|
53
|
-
s.specification_version =
|
58
|
+
s.specification_version = 4
|
54
59
|
|
55
60
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
-
s.add_runtime_dependency(%q<i18n
|
57
|
-
s.add_development_dependency(%q<rspec
|
58
|
-
s.add_development_dependency(%q<rdoc
|
59
|
-
s.add_development_dependency(%q<bundler
|
60
|
-
s.add_development_dependency(%q<jeweler
|
61
|
-
s.add_development_dependency(%q<guard-rspec
|
62
|
-
s.add_development_dependency(%q<localeapp
|
61
|
+
s.add_runtime_dependency(%q<i18n>.freeze, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.9"])
|
63
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 6.2"])
|
64
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 2.0"])
|
65
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
66
|
+
s.add_development_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<localeapp>.freeze, [">= 0"])
|
63
68
|
else
|
64
|
-
s.add_dependency(%q<i18n
|
65
|
-
s.add_dependency(%q<rspec
|
66
|
-
s.add_dependency(%q<rdoc
|
67
|
-
s.add_dependency(%q<bundler
|
68
|
-
s.add_dependency(%q<jeweler
|
69
|
-
s.add_dependency(%q<guard-rspec
|
70
|
-
s.add_dependency(%q<localeapp
|
69
|
+
s.add_dependency(%q<i18n>.freeze, [">= 0"])
|
70
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 3.9"])
|
71
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 6.2"])
|
72
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 2.0"])
|
73
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
74
|
+
s.add_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
75
|
+
s.add_dependency(%q<localeapp>.freeze, [">= 0"])
|
71
76
|
end
|
72
77
|
else
|
73
|
-
s.add_dependency(%q<i18n
|
74
|
-
s.add_dependency(%q<rspec
|
75
|
-
s.add_dependency(%q<rdoc
|
76
|
-
s.add_dependency(%q<bundler
|
77
|
-
s.add_dependency(%q<jeweler
|
78
|
-
s.add_dependency(%q<guard-rspec
|
79
|
-
s.add_dependency(%q<localeapp
|
78
|
+
s.add_dependency(%q<i18n>.freeze, [">= 0"])
|
79
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 3.9"])
|
80
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 6.2"])
|
81
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 2.0"])
|
82
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
83
|
+
s.add_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
84
|
+
s.add_dependency(%q<localeapp>.freeze, [">= 0"])
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
data/lib/iso.rb
CHANGED
@@ -2,7 +2,8 @@ require 'i18n'
|
|
2
2
|
I18n.load_path << Dir[File.join(File.expand_path(File.dirname(__FILE__) + '/../locales'), '*.yml')]
|
3
3
|
I18n.load_path.flatten!
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
require_relative 'iso/tag'
|
6
|
+
require_relative 'iso/subtag'
|
7
|
+
require_relative 'iso/language'
|
8
|
+
require_relative 'iso/region'
|
9
|
+
require_relative 'iso/un/region'
|
data/lib/iso/region.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
class ISO::Region < ISO::Subtag
|
2
|
-
DEFINITIONS_FILE
|
2
|
+
DEFINITIONS_FILE = "#{File.dirname(__FILE__)}/../../data/iso-3166-1.yml"
|
3
3
|
|
4
4
|
def self.identify(full_code)
|
5
5
|
full_code =~ /[-_]([A-Z]{2})$/ ? find($1) : nil
|
6
6
|
end
|
7
7
|
|
8
8
|
private
|
9
|
+
|
9
10
|
def i18n_scope
|
10
11
|
super << ".regions"
|
11
12
|
end
|
data/lib/iso/subtag.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module ISO
|
2
4
|
class Subtag
|
3
5
|
attr_reader :code
|
4
6
|
|
5
7
|
def initialize(code, options={})
|
6
8
|
@code = code
|
9
|
+
@options = options
|
7
10
|
end
|
8
11
|
|
9
12
|
def ==(object)
|
@@ -11,7 +14,7 @@ module ISO
|
|
11
14
|
end
|
12
15
|
|
13
16
|
def name
|
14
|
-
I18n.t(code, :scope => i18n_scope)
|
17
|
+
@options[:name] || I18n.t(code, :scope => i18n_scope)
|
15
18
|
end
|
16
19
|
|
17
20
|
def full_name
|
data/lib/iso/tag.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module ISO
|
2
|
+
module UN
|
3
|
+
class Region < ISO::Region
|
4
|
+
DEFINITIONS_FILE = "#{File.dirname(__FILE__)}/../../../data/un-m49.yml"
|
5
|
+
|
6
|
+
attr_reader :iso_code
|
7
|
+
|
8
|
+
def initialize(code, options={})
|
9
|
+
@iso_code = options[:iso_code]
|
10
|
+
super(code, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
return super if iso_code.nil?
|
15
|
+
@options[:name] || I18n.t(iso_code, :scope => i18n_scope)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.identify(full_code)
|
19
|
+
full_code =~ /-(\d{3})$/ ? find($1) : nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/locales/en.yml
CHANGED
@@ -187,6 +187,42 @@ en:
|
|
187
187
|
zh: Chinese
|
188
188
|
zu: Zulu
|
189
189
|
regions:
|
190
|
+
'002': Africa
|
191
|
+
'005': South America
|
192
|
+
'009': Oceania
|
193
|
+
'011': Western Africa
|
194
|
+
'013': Central America
|
195
|
+
'014': Eastern Africa
|
196
|
+
'015': Northern Africa
|
197
|
+
'017': Middle Africa
|
198
|
+
'018': Southern Africa
|
199
|
+
'019': Americas
|
200
|
+
'021': Northern Americab
|
201
|
+
'029': Caribbean
|
202
|
+
'030': Eastern Asia
|
203
|
+
'034': Southern Asia
|
204
|
+
'035': South-Eastern Asia
|
205
|
+
'039': Southern Europe
|
206
|
+
'053': Australia and New Zealand
|
207
|
+
'054': Melanesia
|
208
|
+
'057': Micronesia
|
209
|
+
'061': Polynesia
|
210
|
+
'142': Asia
|
211
|
+
'143': Central Asia
|
212
|
+
'145': Western Asia
|
213
|
+
'150': Europe
|
214
|
+
'151': Eastern Europe
|
215
|
+
'154': Northern Europe
|
216
|
+
'155': Western Europe
|
217
|
+
'248': Land Islands
|
218
|
+
'344': China, Hong Kong Special Administrative Region
|
219
|
+
'419': Latin America and the Caribbean
|
220
|
+
'446': China, Macao Special Administrative Region
|
221
|
+
'531': Curaçao
|
222
|
+
'535': Bonaire, Saint Eustatius and Saba
|
223
|
+
'638': Runion
|
224
|
+
'680': Sark
|
225
|
+
'830': Channel Islands
|
190
226
|
AF: Afghanistan
|
191
227
|
AX: Aland Islands
|
192
228
|
AL: Albania
|
@@ -227,6 +263,7 @@ en:
|
|
227
263
|
CM: Cameroon
|
228
264
|
CA: Canada
|
229
265
|
CV: Cape Verde
|
266
|
+
CW: Curaçao
|
230
267
|
KY: Cayman Islands
|
231
268
|
CF: Central African Republic
|
232
269
|
TD: Chad
|
data/locales/fr.yml
CHANGED
@@ -4,50 +4,50 @@ describe ISO::Language do
|
|
4
4
|
let(:language) { ISO::Language.new('de', name: 'German') }
|
5
5
|
|
6
6
|
it "is a ISO Subtag" do
|
7
|
-
language.
|
7
|
+
expect(language).to be_kind_of(ISO::Subtag)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "has a code" do
|
11
|
-
language.code.
|
11
|
+
expect(language.code).to eq 'de'
|
12
12
|
end
|
13
13
|
|
14
14
|
it "has a name" do
|
15
|
-
language.name.
|
15
|
+
expect(language.name).to eq 'German'
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#plural_rule_names" do
|
19
19
|
it "defaults to %w(one other)" do
|
20
|
-
language.plural_rule_names.
|
20
|
+
expect(language.plural_rule_names).to eq ISO::Language::DEFAULT_PLURAL_RULE_NAMES
|
21
21
|
end
|
22
22
|
|
23
23
|
it "is overwriteable" do
|
24
24
|
language = ISO::Language.new('ja', plural_rule_names: ['other'])
|
25
|
-
language.plural_rule_names.
|
25
|
+
expect(language.plural_rule_names).to eq ['other']
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#direction" do
|
30
30
|
it "defaults to 'ltr'" do
|
31
|
-
language.direction.
|
31
|
+
expect(language.direction).to eq 'ltr'
|
32
32
|
end
|
33
33
|
|
34
34
|
it "is overwriteable" do
|
35
35
|
language = ISO::Language.new('ar', direction: :rtl)
|
36
|
-
language.direction.
|
36
|
+
expect(language.direction).to eq :rtl
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe ".identify(full_code)" do
|
41
41
|
it "identifies from 'de'" do
|
42
|
-
ISO::Language.identify('de').
|
42
|
+
expect(ISO::Language.identify('de')).to eq ISO::Language.new('de')
|
43
43
|
end
|
44
44
|
|
45
45
|
it "identifies from 'fr-CH'" do
|
46
|
-
ISO::Language.identify('fr-CH').
|
46
|
+
expect(ISO::Language.identify('fr-CH')).to eq ISO::Language.new('fr')
|
47
47
|
end
|
48
48
|
|
49
49
|
it "returns nil when it can't identify" do
|
50
|
-
ISO::Language.identify('csb').
|
50
|
+
expect(ISO::Language.identify('csb')).to be_nil
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/spec/lib/iso/region_spec.rb
CHANGED
@@ -4,28 +4,28 @@ describe ISO::Region do
|
|
4
4
|
let(:region) { ISO::Region.new('FR', name: 'France') }
|
5
5
|
|
6
6
|
it "is a ISO Subtag" do
|
7
|
-
region.
|
7
|
+
expect(region).to be_kind_of(ISO::Subtag)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "has a code" do
|
11
|
-
region.code.
|
11
|
+
expect(region.code).to eq 'FR'
|
12
12
|
end
|
13
13
|
|
14
14
|
it "has a name" do
|
15
|
-
region.name.
|
15
|
+
expect(region.name).to eq 'France'
|
16
16
|
end
|
17
17
|
|
18
18
|
describe ".identify(full_code)" do
|
19
19
|
it "identifies from 'fr-CH'" do
|
20
|
-
ISO::Region.identify('fr-CH').
|
20
|
+
expect(ISO::Region.identify('fr-CH')).to eq ISO::Region.find('CH')
|
21
21
|
end
|
22
22
|
|
23
23
|
it "identifies from 'es_MX" do
|
24
|
-
ISO::Region.identify('es_MX').
|
24
|
+
expect(ISO::Region.identify('es_MX')).to eq ISO::Region.find('MX')
|
25
25
|
end
|
26
26
|
|
27
27
|
it "returns nil when it can't identify" do
|
28
|
-
ISO::Region.identify('gsw').
|
28
|
+
expect(ISO::Region.identify('gsw')).to be_nil
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/spec/lib/iso/subtag_spec.rb
CHANGED
@@ -12,52 +12,68 @@ end
|
|
12
12
|
describe ISO::Subtag do
|
13
13
|
describe "#==(object)" do
|
14
14
|
it "returns true when both have the same code" do
|
15
|
-
ISO::Region.find('SY').
|
15
|
+
expect(ISO::Region.find('SY')).to eq ISO::Region.find('SY')
|
16
16
|
end
|
17
17
|
|
18
18
|
it "returns false when they have different codes" do
|
19
|
-
ISO::Region.find('FR').
|
19
|
+
expect(ISO::Region.find('FR')).to_not eq ISO::Region.find('GB')
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
describe "#name" do
|
24
|
+
let(:fake_region) { ISO::Subtag.new('FR', name: 'This is a lie') }
|
25
|
+
let(:mars) { ISO::Subtag.new('MRS') }
|
26
|
+
|
27
|
+
it 'will accept a name option' do
|
28
|
+
expect(I18n).to_not receive(:t)
|
29
|
+
expect(fake_region.name).to eq 'This is a lie'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'falls back to the translation' do
|
33
|
+
expect(I18n).to receive(:t).with('MRS', scope: 'vendor.iso').and_return('Mars')
|
34
|
+
expect(mars.name).to eq 'Mars'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
23
39
|
describe "#full_name" do
|
24
40
|
it "is composed of the code and the name" do
|
25
41
|
full_name = Subtag.find('fr').full_name
|
26
|
-
full_name.
|
27
|
-
full_name.
|
42
|
+
expect(full_name).to match(/fr/)
|
43
|
+
expect(full_name).to match(/French/)
|
28
44
|
end
|
29
45
|
end
|
30
46
|
|
31
47
|
describe ".all" do
|
32
48
|
it "gets its definition from the DEFINITIONS_FILE" do
|
33
49
|
subtags = Subtag.all
|
34
|
-
subtags[0].
|
35
|
-
subtags[1].
|
36
|
-
subtags[2].
|
50
|
+
expect(subtags[0]).to eq Subtag.find('en')
|
51
|
+
expect(subtags[1]).to eq Subtag.find('fr')
|
52
|
+
expect(subtags[2]).to eq Subtag.find('de')
|
37
53
|
end
|
38
54
|
end
|
39
55
|
|
40
56
|
describe ".find(code)" do
|
41
57
|
it "finds a subtag by code" do
|
42
58
|
subtag = Subtag.find('de')
|
43
|
-
subtag.code.
|
44
|
-
subtag.name.
|
59
|
+
expect(subtag.code).to eq 'de'
|
60
|
+
expect(subtag.name).to eq 'German'
|
45
61
|
end
|
46
62
|
|
47
63
|
it "returns nil when no language can be found" do
|
48
|
-
Subtag.find('xxxx').
|
64
|
+
expect(Subtag.find('xxxx')).to be_nil
|
49
65
|
end
|
50
66
|
end
|
51
67
|
|
52
68
|
describe ".default" do
|
53
69
|
it "finds from DEFAULT_CODE" do
|
54
|
-
Subtag.default.
|
70
|
+
expect(Subtag.default).to eq Subtag.find('fr')
|
55
71
|
end
|
56
72
|
end
|
57
73
|
|
58
74
|
describe ".codes" do
|
59
75
|
it "returns an array of all codes" do
|
60
|
-
Subtag.codes.
|
76
|
+
expect(Subtag.codes).to eq %w(en fr de)
|
61
77
|
end
|
62
78
|
end
|
63
79
|
end
|
data/spec/lib/iso/tag_spec.rb
CHANGED
@@ -4,74 +4,91 @@ describe ISO::Tag do
|
|
4
4
|
describe ".new(code)" do
|
5
5
|
it "returns a tag containing the language and region" do
|
6
6
|
tag = ISO::Tag.new('en-MX')
|
7
|
-
tag.language.code.
|
8
|
-
tag.region.code.
|
7
|
+
expect(tag.language.code).to eq 'en'
|
8
|
+
expect(tag.region.code).to eq 'MX'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns a tag containing the language and UN region" do
|
12
|
+
tag = ISO::Tag.new('en-419')
|
13
|
+
expect(tag.language.code).to eq 'en'
|
14
|
+
expect(tag.region.code).to eq '419'
|
9
15
|
end
|
10
16
|
|
11
17
|
it "returns a tag containing the language only" do
|
12
18
|
tag = ISO::Tag.new('en-XXXXXX')
|
13
|
-
tag.language.code.
|
14
|
-
tag.region.
|
19
|
+
expect(tag.language.code).to eq 'en'
|
20
|
+
expect(tag.region).to be_nil
|
15
21
|
end
|
16
22
|
|
17
23
|
it "returns a tag containing the region only" do
|
18
24
|
tag = ISO::Tag.new('gsw-CH')
|
19
|
-
tag.language.
|
20
|
-
tag.region.code.
|
25
|
+
expect(tag.language).to be_nil
|
26
|
+
expect(tag.region.code).to eq 'CH'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns a tag containing the UN region only" do
|
30
|
+
tag = ISO::Tag.new('gsw-419')
|
31
|
+
expect(tag.language).to be_nil
|
32
|
+
expect(tag.region.code).to eq '419'
|
21
33
|
end
|
22
34
|
|
23
35
|
it "returns a tag containing no language or region" do
|
24
36
|
tag = ISO::Tag.new('csb-XXXXXX')
|
25
|
-
tag.language.
|
26
|
-
tag.region.
|
37
|
+
expect(tag.language).to be_nil
|
38
|
+
expect(tag.region).to be_nil
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
30
42
|
describe "#codes" do
|
31
43
|
it "returns an array containing each subtag's code" do
|
32
|
-
ISO::Tag.new('en-US').codes.
|
44
|
+
expect(ISO::Tag.new('en-US').codes).to eq %w(en US)
|
33
45
|
end
|
34
46
|
end
|
35
47
|
|
36
48
|
describe "#subtags" do
|
37
49
|
it "returns an array containing the language" do
|
38
50
|
tag = ISO::Tag.new('fr')
|
39
|
-
tag.subtags.size.
|
40
|
-
tag.subtags.first.
|
41
|
-
tag.subtags.first.code.
|
51
|
+
expect(tag.subtags.size).to eq 1
|
52
|
+
expect(tag.subtags.first).to be_kind_of(ISO::Language)
|
53
|
+
expect(tag.subtags.first.code).to eq 'fr'
|
42
54
|
end
|
43
55
|
|
44
56
|
it "returns an array containing the language and the region" do
|
45
57
|
tag = ISO::Tag.new('fr-CH')
|
46
|
-
tag.subtags.size.
|
58
|
+
expect(tag.subtags.size).to eq 2
|
47
59
|
|
48
|
-
tag.subtags.first.
|
49
|
-
tag.subtags.first.code.
|
60
|
+
expect(tag.subtags.first).to be_kind_of(ISO::Language)
|
61
|
+
expect(tag.subtags.first.code).to eq 'fr'
|
50
62
|
|
51
|
-
tag.subtags.last.
|
52
|
-
tag.subtags.last.code.
|
63
|
+
expect(tag.subtags.last).to be_kind_of(ISO::Region)
|
64
|
+
expect(tag.subtags.last.code).to eq 'CH'
|
53
65
|
end
|
54
66
|
end
|
55
67
|
|
56
68
|
describe "#valid?" do
|
57
69
|
it "returns true when a valid language is supplied" do
|
58
|
-
ISO::Tag.new('da').
|
70
|
+
expect(ISO::Tag.new('da')).to be_valid
|
59
71
|
end
|
60
72
|
|
61
73
|
it "returns true when a valid language and region are supplied" do
|
62
|
-
ISO::Tag.new('da-AT').
|
74
|
+
expect(ISO::Tag.new('da-AT')).to be_valid
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns true when a valid language an UN region are supplied" do
|
78
|
+
expect(ISO::Tag.new('es-419')).to be_valid
|
63
79
|
end
|
64
80
|
|
65
81
|
it "returns false when no code is supplied" do
|
66
|
-
ISO::Tag.new('').
|
82
|
+
expect(ISO::Tag.new('')).to_not be_valid
|
67
83
|
end
|
68
84
|
|
69
85
|
it "returns false when supplied language is invalid" do
|
70
|
-
ISO::Tag.new('lol').
|
86
|
+
expect(ISO::Tag.new('lol')).to_not be_valid
|
71
87
|
end
|
72
88
|
|
73
89
|
it "returns false when supplied region is invalid" do
|
74
|
-
ISO::Tag.new('en-lol').
|
90
|
+
expect(ISO::Tag.new('en-lol')).to_not be_valid
|
75
91
|
end
|
92
|
+
|
76
93
|
end
|
77
94
|
end
|