language_list 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f694a7105df99148d7a9f8a7d2a8bfceceac7a1
4
- data.tar.gz: 7d45966d267cee5b931269a4e97e68533cf5e437
3
+ metadata.gz: '068bbf4dc0c63ec1a2f51b7f88d04359d6343c3c'
4
+ data.tar.gz: 72465669955bcd970f4bb8caff0ed2d0a5bfff7f
5
5
  SHA512:
6
- metadata.gz: e76121fbd53e3317ca32d4e65a39670589f115dbea52923bc9f4d9e11d912e87faa227aeb386bc3b592e01a0ada009405c8039e24a480b58ce671a5880b4527e
7
- data.tar.gz: b2566e64c6bda74ce1f308e3113a5d11fade539a1eecbb5f84092ecbfb8fbcdb9751e3ede3df44a595e1f85ed268dea66d9d636742e4f85c35f2bf5e89b443b0
6
+ metadata.gz: 6c29043d299c748cf72a34b00be615aa8faa787f54558a73321f4461c2a6747aeba62eddc855b9d52edb0ea35a758660761e7be5c2a94eaf001ca521e3a5329e
7
+ data.tar.gz: 7f685621ee567bde0a23d14b89a74422423545f66a0b60ede9aada402f7d60d50f338c776c57de57a7fc92c409676561e3fb295ea8d6dbdd24e117201ee46f26
@@ -1,12 +1,15 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.4.0
4
+ - 2.3
3
5
  - 2.2
4
6
  - 2.1
5
7
  - 1.9.3
6
8
  - jruby-18mode
7
9
  - jruby-19mode
8
- - rbx-18mode
9
- - rbx-19mode
10
10
  - 1.8.7
11
11
 
12
+ before_install:
13
+ - gem update bundler
14
+
12
15
  script: bundle exec rake test
data/README.md CHANGED
@@ -7,7 +7,7 @@ A list of languages based upon ISO-639-1 and ISO-639-3 with functions to retriev
7
7
  # Get an array of LanguageList::LanguageInfo classes
8
8
  all_languages = LanguageList::ALL_LANGUAGES
9
9
  common_languages = LanguageList::COMMON_LANGUAGES
10
-
10
+
11
11
  # Finding a language based on its ISO-639-1 or ISO-639-3 code or
12
12
  # name
13
13
  german = LanguageList::LanguageInfo.find('German')
@@ -21,6 +21,12 @@ A list of languages based upon ISO-639-1 and ISO-639-3 with functions to retriev
21
21
 
22
22
  rake
23
23
 
24
+ ## Upgrading
25
+
26
+ ### 1.1 to 1.2
27
+
28
+ * Version 1.2 freezes all of the constants once they're loaded.
29
+
24
30
  ## Thanks
25
31
  Thanks goes to Steve Hardie for his work on creating a list of common languages (http://stevehardie.com/2009/10/list-of-common-languages/).
26
32
 
data/data/dump CHANGED
Binary file
@@ -2,13 +2,15 @@ require 'yaml'
2
2
 
3
3
  module LanguageList
4
4
  class LanguageInfo
5
- attr_reader :name, :iso_639_3, :iso_639_1, :type
5
+ attr_reader :name, :iso_639_3, :iso_639_1, :iso_639_2b, :iso_639_2t, :type
6
6
 
7
7
  def initialize(options)
8
8
  @name = options[:name]
9
9
  @common_name = options[:common_name]
10
10
  @iso_639_3 = options[:iso_639_3]
11
11
  @iso_639_1 = options[:iso_639_1]
12
+ @iso_639_2b = options[:iso_639_2b]
13
+ @iso_639_2t = options[:iso_639_2t]
12
14
  @common = options[:common]
13
15
  @type = options[:type]
14
16
  end
@@ -47,12 +49,25 @@ module LanguageList
47
49
  LanguageList::BY_ISO_639_3[code]
48
50
  end
49
51
 
52
+ def self.find_by_iso_639_2b(code)
53
+ LanguageList::BY_ISO_639_2B[code]
54
+ end
55
+
56
+ def self.find_by_iso_639_2t(code)
57
+ LanguageList::BY_ISO_639_2T[code]
58
+ end
59
+
50
60
  def self.find_by_name(name)
51
- LanguageList::BY_NAME[name]
61
+ LanguageList::BY_NAME[name.downcase]
52
62
  end
53
63
 
54
64
  def self.find(code)
55
- find_by_iso_639_1(code) || find_by_iso_639_3(code) || find_by_name(code)
65
+ code.downcase!
66
+ find_by_iso_639_1(code) ||
67
+ find_by_iso_639_3(code) ||
68
+ find_by_iso_639_2b(code) ||
69
+ find_by_iso_639_2t(code) ||
70
+ find_by_name(code)
56
71
  end
57
72
  end
58
73
 
@@ -62,18 +77,26 @@ module LanguageList
62
77
  warn "Reverting to hash load: #{e.message}"
63
78
  yaml_data = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__),'..', 'data', 'languages.yml')))
64
79
  yaml_data.map{|e| LanguageInfo.new(e) }
65
- end
66
- ISO_639_1 = ALL_LANGUAGES.select(&:iso_639_1?)
67
- LIVING_LANGUAGES = ALL_LANGUAGES.select(&:living?)
68
- COMMON_LANGUAGES = ALL_LANGUAGES.select(&:common?)
80
+ end.freeze
81
+ ISO_639_1 = ALL_LANGUAGES.select(&:iso_639_1?).freeze
82
+ LIVING_LANGUAGES = ALL_LANGUAGES.select(&:living?).freeze
83
+ COMMON_LANGUAGES = ALL_LANGUAGES.select(&:common?).freeze
69
84
 
70
85
  BY_NAME = {}
71
86
  BY_ISO_639_1 = {}
72
87
  BY_ISO_639_3 = {}
88
+ BY_ISO_639_2B = {}
89
+ BY_ISO_639_2T = {}
73
90
  ALL_LANGUAGES.each do |lang|
74
- BY_NAME[lang.name] = lang
91
+ BY_NAME[lang.name.downcase] = lang
75
92
  BY_ISO_639_1[lang.iso_639_1] = lang if lang.iso_639_1
76
93
  BY_ISO_639_3[lang.iso_639_3] = lang if lang.iso_639_3
94
+ BY_ISO_639_2B[lang.iso_639_2b] = lang if lang.iso_639_2b
95
+ BY_ISO_639_2T[lang.iso_639_2t] = lang if lang.iso_639_2t
77
96
  end
78
-
97
+ BY_NAME.freeze
98
+ BY_ISO_639_1.freeze
99
+ BY_ISO_639_3.freeze
100
+ BY_ISO_639_2B.freeze
101
+ BY_ISO_639_2T.freeze
79
102
  end
@@ -1,3 +1,3 @@
1
1
  module LanguageList
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -36,6 +36,15 @@ class LanguageListTest < Minitest::Test
36
36
  english = LanguageList::LanguageInfo.find_by_name('English')
37
37
  assert_equal 'en', english.iso_639_1
38
38
  assert_equal 'eng', english.iso_639_3
39
+ assert_equal 'eng', english.iso_639_2b
40
+ assert_equal 'eng', english.iso_639_2t
41
+ assert_equal 'English', english.name
42
+ end
43
+
44
+ def test_case_insensitive_find_by_name
45
+ english = LanguageList::LanguageInfo.find_by_name('english')
46
+ assert_equal 'en', english.iso_639_1
47
+ assert_equal 'eng', english.iso_639_3
39
48
  assert_equal 'English', english.name
40
49
  end
41
50
 
@@ -46,6 +55,49 @@ class LanguageListTest < Minitest::Test
46
55
  assert_equal 'English', english.name
47
56
  end
48
57
 
58
+ def test_case_insensitive_find_with_iso_639_1_code
59
+ english = LanguageList::LanguageInfo.find('EN')
60
+ assert_equal 'en', english.iso_639_1
61
+ assert_equal 'eng', english.iso_639_3
62
+ assert_equal 'English', english.name
63
+ end
64
+
65
+ def test_find_with_iso_639_2b_code
66
+ macedonian = LanguageList::LanguageInfo.find('mac')
67
+ assert_equal 'mk', macedonian.iso_639_1
68
+ assert_equal 'mac', macedonian.iso_639_2b
69
+ assert_equal 'mkd', macedonian.iso_639_2t
70
+ assert_equal 'mkd', macedonian.iso_639_3
71
+ assert_equal 'Macedonian', macedonian.name
72
+ end
73
+
74
+ def test_case_insensitive_find_with_iso_639_2b_code
75
+ macedonian = LanguageList::LanguageInfo.find('MAC')
76
+ assert_equal 'mk', macedonian.iso_639_1
77
+ assert_equal 'mac', macedonian.iso_639_2b
78
+ assert_equal 'mkd', macedonian.iso_639_2t
79
+ assert_equal 'mkd', macedonian.iso_639_3
80
+ assert_equal 'Macedonian', macedonian.name
81
+ end
82
+
83
+ def test_find_with_iso_639_2t_code
84
+ macedonian = LanguageList::LanguageInfo.find('mkd')
85
+ assert_equal 'mk', macedonian.iso_639_1
86
+ assert_equal 'mac', macedonian.iso_639_2b
87
+ assert_equal 'mkd', macedonian.iso_639_2t
88
+ assert_equal 'mkd', macedonian.iso_639_3
89
+ assert_equal 'Macedonian', macedonian.name
90
+ end
91
+
92
+ def test_case_insensitive_find_with_iso_639_2t_code
93
+ macedonian = LanguageList::LanguageInfo.find('MKD')
94
+ assert_equal 'mk', macedonian.iso_639_1
95
+ assert_equal 'mac', macedonian.iso_639_2b
96
+ assert_equal 'mkd', macedonian.iso_639_2t
97
+ assert_equal 'mkd', macedonian.iso_639_3
98
+ assert_equal 'Macedonian', macedonian.name
99
+ end
100
+
49
101
  def test_find_with_iso_639_3_code
50
102
  english = LanguageList::LanguageInfo.find('eng')
51
103
  assert_equal 'en', english.iso_639_1
@@ -53,10 +105,19 @@ class LanguageListTest < Minitest::Test
53
105
  assert_equal 'English', english.name
54
106
  end
55
107
 
108
+ def test_case_insensitive_find_with_iso_639_3_code
109
+ english = LanguageList::LanguageInfo.find('Eng')
110
+ assert_equal 'en', english.iso_639_1
111
+ assert_equal 'eng', english.iso_639_3
112
+ assert_equal 'English', english.name
113
+ end
114
+
56
115
  def test_find_with_name
57
116
  english = LanguageList::LanguageInfo.find('English')
58
117
  assert_equal 'en', english.iso_639_1
59
118
  assert_equal 'eng', english.iso_639_3
119
+ assert_equal 'eng', english.iso_639_2b
120
+ assert_equal 'eng', english.iso_639_2t
60
121
  assert_equal 'English', english.name
61
122
  end
62
123
 
@@ -76,4 +137,42 @@ class LanguageListTest < Minitest::Test
76
137
  english = LanguageList::LanguageInfo.find('en')
77
138
  assert_equal english.name, english.common_name
78
139
  end
140
+
141
+ def test_cannot_change_constants
142
+ assert_raises RuntimeError, TypeError do
143
+ LanguageList::ALL_LANGUAGES[0] = nil
144
+ end
145
+
146
+ assert_raises RuntimeError, TypeError do
147
+ LanguageList::ISO_639_1[0] = nil
148
+ end
149
+
150
+ assert_raises RuntimeError, TypeError do
151
+ LanguageList::LIVING_LANGUAGES[0] = nil
152
+ end
153
+
154
+ assert_raises RuntimeError, TypeError do
155
+ LanguageList::COMMON_LANGUAGES[0] = nil
156
+ end
157
+
158
+ assert_raises RuntimeError, TypeError do
159
+ LanguageList::BY_NAME[0] = nil
160
+ end
161
+
162
+ assert_raises RuntimeError, TypeError do
163
+ LanguageList::BY_ISO_639_1[0] = nil
164
+ end
165
+
166
+ assert_raises RuntimeError, TypeError do
167
+ LanguageList::BY_ISO_639_3[0] = nil
168
+ end
169
+
170
+ assert_raises RuntimeError, TypeError do
171
+ LanguageList::BY_ISO_639_2T[0] = nil
172
+ end
173
+
174
+ assert_raises RuntimeError, TypeError do
175
+ LanguageList::BY_ISO_639_2B[0] = nil
176
+ end
177
+ end
79
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: language_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2017-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  requirements: []
80
80
  rubyforge_project: language_list
81
- rubygems_version: 2.2.2
81
+ rubygems_version: 2.5.2
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: A list of languages and methods to find and work with these languages.