iso639 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/iso639/language.rb +12 -4
- data/lib/iso639/version.rb +1 -1
- data/lib/iso639.rb +2 -6
- data/test/iso639_test.rb +1 -1
- data/test/language_test.rb +12 -0
- metadata +1 -1
data/lib/iso639/language.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Iso639
|
2
2
|
class Language
|
3
|
-
attr_reader :alpha3_bibliographic, :alpha3_terminology, :alpha2, :
|
3
|
+
attr_reader :alpha3_bibliographic, :alpha3_terminology, :alpha2, :english_names, :french_names
|
4
4
|
alias_method :alpha3, :alpha3_bibliographic
|
5
|
-
alias_method :name, :english_name
|
6
5
|
|
7
6
|
# Public: Initialize a Language.
|
8
7
|
#
|
@@ -15,8 +14,17 @@ module Iso639
|
|
15
14
|
@alpha3_bibliographic = strip_to_nil(alpha3_bibliographic)
|
16
15
|
@alpha3_terminology = strip_to_nil(alpha3_terminology)
|
17
16
|
@alpha2 = strip_to_nil(alpha2)
|
18
|
-
@
|
19
|
-
@
|
17
|
+
@english_names = english_name.split(/;\s*/).map { |n| strip_to_nil(n) }
|
18
|
+
@french_names = french_name.split(/;\s*/).map { |n| strip_to_nil(n) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def english_name
|
22
|
+
english_names.first
|
23
|
+
end
|
24
|
+
alias_method :name, :english_name
|
25
|
+
|
26
|
+
def french_name
|
27
|
+
french_names.first
|
20
28
|
end
|
21
29
|
|
22
30
|
def to_s
|
data/lib/iso639/version.rb
CHANGED
data/lib/iso639.rb
CHANGED
@@ -41,12 +41,8 @@ module Iso639
|
|
41
41
|
LanguagesByAlpha2[lang.alpha2] = lang if lang.alpha2
|
42
42
|
LanguagesByAlpha3[lang.alpha3] = lang if lang.alpha3
|
43
43
|
LanguagesByAlpha3Terminology[lang.alpha3_terminology] = lang if lang.alpha3_terminology
|
44
|
-
lang.
|
45
|
-
|
46
|
-
end
|
47
|
-
lang.french_name.split(/;\s*/).each do |name|
|
48
|
-
LanguagesByFrenchName[name] = lang
|
49
|
-
end
|
44
|
+
lang.english_names.each { |name| LanguagesByName[name] = lang }
|
45
|
+
lang.french_names.each { |name| LanguagesByFrenchName[name] = lang }
|
50
46
|
end
|
51
47
|
|
52
48
|
# Public: Find a language by any common lookup value
|
data/test/iso639_test.rb
CHANGED
@@ -52,7 +52,7 @@ describe Iso639::LanguagesByEnglishName do
|
|
52
52
|
assert_equal "German", Iso639::LanguagesByName["german"].name
|
53
53
|
assert_equal "spa", Iso639::LanguagesByName["spanish"].alpha3
|
54
54
|
assert_equal "klingon", Iso639::LanguagesByName["Klingon"].french_name
|
55
|
-
assert_equal "Klingon
|
55
|
+
assert_equal "Klingon", Iso639::LanguagesByName["tlhIngan-Hol"].name
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should return nil for unknown codes" do
|
data/test/language_test.rb
CHANGED
@@ -39,6 +39,18 @@ describe Iso639::Language do
|
|
39
39
|
assert_equal "English", "#{lang}"
|
40
40
|
end
|
41
41
|
|
42
|
+
it "should handle multiple english names" do
|
43
|
+
lang = Iso639::Language.new "", "", "", "Spanish; Castilian", ""
|
44
|
+
assert_equal "Spanish", lang.name
|
45
|
+
assert_equal ["Spanish", "Castilian"], lang.english_names
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should handle multiple french names" do
|
49
|
+
lang = Iso639::Language.new "", "", "", "", "espagnol; castillan"
|
50
|
+
assert_equal "espagnol", lang.french_name
|
51
|
+
assert_equal ["espagnol", "castillan"], lang.french_names
|
52
|
+
end
|
53
|
+
|
42
54
|
it "should not be mutable" do
|
43
55
|
lang = Iso639::Language.new("eng", nil, "en", "English", "anglais").freeze
|
44
56
|
begin
|