iso 0.1.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 = %q{iso}
8
- s.version = "0.1.1"
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.authors = [%q{Christopher Dell}]
12
- s.date = %q{2012-10-25}
13
- s.description = %q{A subset of the ISO spec implemented in ruby}
14
- s.email = %q{chris@tigrish.com}
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 = %q{http://github.com/tigrish/iso}
47
- s.licenses = [%q{MIT}]
48
- s.require_paths = [%q{lib}]
49
- s.rubygems_version = %q{1.8.6}
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 = 3
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>, [">= 0"])
57
- s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
58
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
59
- s.add_development_dependency(%q<bundler>, ["~> 1.2.0"])
60
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
61
- s.add_development_dependency(%q<guard-rspec>, [">= 0"])
62
- s.add_development_dependency(%q<localeapp>, [">= 0"])
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>, [">= 0"])
65
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
66
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
67
- s.add_dependency(%q<bundler>, ["~> 1.2.0"])
68
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
69
- s.add_dependency(%q<guard-rspec>, [">= 0"])
70
- s.add_dependency(%q<localeapp>, [">= 0"])
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>, [">= 0"])
74
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
75
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
76
- s.add_dependency(%q<bundler>, ["~> 1.2.0"])
77
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
78
- s.add_dependency(%q<guard-rspec>, [">= 0"])
79
- s.add_dependency(%q<localeapp>, [">= 0"])
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
- require 'iso/tag'
6
- require 'iso/subtag'
7
- require 'iso/language'
8
- require 'iso/region'
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'
@@ -1,11 +1,12 @@
1
1
  class ISO::Region < ISO::Subtag
2
- DEFINITIONS_FILE = "#{File.dirname(__FILE__)}/../../data/iso-3166-1.yml"
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
@@ -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
@@ -5,7 +5,7 @@ module ISO
5
5
  def initialize(code)
6
6
  @code = code
7
7
  @language = Language.identify(code)
8
- @region = Region.identify(code)
8
+ @region = Region.identify(code) || UN::Region.identify(code)
9
9
  end
10
10
 
11
11
  def codes
@@ -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
@@ -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
@@ -227,6 +227,7 @@ fr:
227
227
  CM: Cameroun
228
228
  CA: Canada
229
229
  CV: Cap-Vert
230
+ CW: Curaçao
230
231
  KY: Îles Caïmans
231
232
  CF: République centrafricaine
232
233
  TD: Tchad
@@ -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.should be_kind_of(ISO::Subtag)
7
+ expect(language).to be_kind_of(ISO::Subtag)
8
8
  end
9
9
 
10
10
  it "has a code" do
11
- language.code.should == 'de'
11
+ expect(language.code).to eq 'de'
12
12
  end
13
13
 
14
14
  it "has a name" do
15
- language.name.should == 'German'
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.should == ISO::Language::DEFAULT_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.should == ['other']
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.should == 'ltr'
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.should == :rtl
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').should == ISO::Language.new('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').should == ISO::Language.new('fr')
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').should be_nil
50
+ expect(ISO::Language.identify('csb')).to be_nil
51
51
  end
52
52
  end
53
53
  end
@@ -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.should be_kind_of(ISO::Subtag)
7
+ expect(region).to be_kind_of(ISO::Subtag)
8
8
  end
9
9
 
10
10
  it "has a code" do
11
- region.code.should == 'FR'
11
+ expect(region.code).to eq 'FR'
12
12
  end
13
13
 
14
14
  it "has a name" do
15
- region.name.should == 'France'
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').should == ISO::Region.find('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').should == ISO::Region.find('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').should be_nil
28
+ expect(ISO::Region.identify('gsw')).to be_nil
29
29
  end
30
30
  end
31
31
  end
@@ -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').should == 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').should_not == ISO::Region.find('GB')
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.should match(/fr/)
27
- full_name.should match(/French/)
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].should == Subtag.find('en')
35
- subtags[1].should == Subtag.find('fr')
36
- subtags[2].should == Subtag.find('de')
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.should == 'de'
44
- subtag.name.should == 'German'
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').should be_nil
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.should == Subtag.find('fr')
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.should == %w(en fr de)
76
+ expect(Subtag.codes).to eq %w(en fr de)
61
77
  end
62
78
  end
63
79
  end
@@ -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.should == 'en'
8
- tag.region.code.should == 'MX'
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.should == 'en'
14
- tag.region.should be_nil
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.should be_nil
20
- tag.region.code.should == 'CH'
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.should be_nil
26
- tag.region.should be_nil
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.should == %w(en US)
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.should == 1
40
- tag.subtags.first.should be_kind_of(ISO::Language)
41
- tag.subtags.first.code.should == 'fr'
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.should == 2
58
+ expect(tag.subtags.size).to eq 2
47
59
 
48
- tag.subtags.first.should be_kind_of(ISO::Language)
49
- tag.subtags.first.code.should == 'fr'
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.should be_kind_of(ISO::Region)
52
- tag.subtags.last.code.should == 'CH'
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').should be_valid
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').should be_valid
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('').should_not be_valid
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').should_not be_valid
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').should_not be_valid
90
+ expect(ISO::Tag.new('en-lol')).to_not be_valid
75
91
  end
92
+
76
93
  end
77
94
  end