language_list 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -2
- data/lib/language_list.rb +6 -2
- data/lib/language_list/version.rb +1 -1
- data/test/language_list_test.rb +14 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -6,7 +6,9 @@ A list of languages based upon ISO-639-1 and ISO-639-3 with functions to retriev
|
|
6
6
|
all_languages = LanguageList::ALL_LANGUAGES
|
7
7
|
common_languages = LanguageList::COMMON_LANGUAGES
|
8
8
|
|
9
|
-
# Finding a language based on its ISO-639-1 or ISO-639-3 code
|
9
|
+
# Finding a language based on its ISO-639-1 or ISO-639-3 code or
|
10
|
+
# name
|
11
|
+
german = LanguageList::LanguageInfo.find('German')
|
10
12
|
english = LanguageList::LanguageInfo.find('en')
|
11
13
|
english.name.inspect #=> "English"
|
12
14
|
english.iso_639_1.inspect #=> "en"
|
@@ -19,4 +21,4 @@ Thanks goes to Steve Hardie for his work on creating a list of common languages
|
|
19
21
|
## License
|
20
22
|
I don't actually know the license for this project. The project contains countries from the ISO language list although they were not obtained from the ISO website. The country list has been adapted and placed in data/languages.yml, so that it can be replaced if required.
|
21
23
|
|
22
|
-
All of the code (everything except data/languages.yml) in this project is released under an MIT license.
|
24
|
+
All of the code (everything except data/languages.yml) in this project is released under an MIT license.
|
data/lib/language_list.rb
CHANGED
@@ -42,8 +42,12 @@ module LanguageList
|
|
42
42
|
LanguageList::ALL_LANGUAGES.detect{|l| l.iso_639_3 == code }
|
43
43
|
end
|
44
44
|
|
45
|
+
def self.find_by_name(name)
|
46
|
+
LanguageList::ALL_LANGUAGES.detect{|l| l.name == name }
|
47
|
+
end
|
48
|
+
|
45
49
|
def self.find(code)
|
46
|
-
find_by_iso_639_1(code) || find_by_iso_639_3(code)
|
50
|
+
find_by_iso_639_1(code) || find_by_iso_639_3(code) || find_by_name(code)
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
@@ -52,4 +56,4 @@ module LanguageList
|
|
52
56
|
ISO_639_1 = ALL_LANGUAGES.select(&:iso_639_1?)
|
53
57
|
LIVING_LANGUAGES = ALL_LANGUAGES.select(&:living?)
|
54
58
|
COMMON_LANGUAGES = ALL_LANGUAGES.select(&:common?)
|
55
|
-
end
|
59
|
+
end
|
data/test/language_list_test.rb
CHANGED
@@ -35,6 +35,13 @@ class LanguageListTest < Test::Unit::TestCase
|
|
35
35
|
assert_equal 'English', english.name
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_find_by_name
|
39
|
+
english = LanguageList::LanguageInfo.find_by_name('English')
|
40
|
+
assert_equal 'en', english.iso_639_1
|
41
|
+
assert_equal 'eng', english.iso_639_3
|
42
|
+
assert_equal 'English', english.name
|
43
|
+
end
|
44
|
+
|
38
45
|
def test_find_with_iso_639_1_code
|
39
46
|
english = LanguageList::LanguageInfo.find('en')
|
40
47
|
assert_equal 'en', english.iso_639_1
|
@@ -49,6 +56,13 @@ class LanguageListTest < Test::Unit::TestCase
|
|
49
56
|
assert_equal 'English', english.name
|
50
57
|
end
|
51
58
|
|
59
|
+
def test_find_with_name
|
60
|
+
english = LanguageList::LanguageInfo.find('English')
|
61
|
+
assert_equal 'en', english.iso_639_1
|
62
|
+
assert_equal 'eng', english.iso_639_3
|
63
|
+
assert_equal 'English', english.name
|
64
|
+
end
|
65
|
+
|
52
66
|
def test_sort_should_order_by_name
|
53
67
|
sorted = LanguageList::COMMON_LANGUAGES.sort
|
54
68
|
expected = LanguageList::COMMON_LANGUAGES.map(&:name).sort
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: language_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A list of languages based upon ISO-639-1 and ISO-639-3 with functions
|
15
15
|
to retrieve only common languages.
|
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
48
|
version: '0'
|
49
49
|
requirements: []
|
50
50
|
rubyforge_project: language_list
|
51
|
-
rubygems_version: 1.8.
|
51
|
+
rubygems_version: 1.8.17
|
52
52
|
signing_key:
|
53
53
|
specification_version: 3
|
54
54
|
summary: A list of languages and methods to find and work with these langauges.
|