iso639 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,7 @@
1
1
  module Iso639
2
2
  class Language
3
- attr_reader :alpha3_bibliographic, :alpha3_terminology, :alpha2, :english_name, :french_name
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
- @english_name = strip_to_nil(english_name)
19
- @french_name = strip_to_nil(french_name)
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
@@ -1,3 +1,3 @@
1
1
  module Iso639
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
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.name.split(/;\s*/).each do |name|
45
- LanguagesByName[name] = lang
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; tlhIngan-Hol", Iso639::LanguagesByName["tlhIngan-Hol"].name
55
+ assert_equal "Klingon", Iso639::LanguagesByName["tlhIngan-Hol"].name
56
56
  end
57
57
 
58
58
  it "should return nil for unknown codes" do
@@ -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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: iso639
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.4
5
+ version: 1.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan McGeary