iso639 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/iso639.rb +1 -1
- data/lib/iso639/language.rb +11 -10
- data/lib/iso639/version.rb +1 -1
- data/test/iso639_test.rb +4 -1
- data/test/language_test.rb +6 -0
- metadata +16 -16
data/README.md
CHANGED
@@ -33,7 +33,7 @@ Iso639["en"] # => "English"
|
|
33
33
|
Iso639["en"].alpha2 # => "en"
|
34
34
|
Iso639["en"].alpha3 # => "eng"
|
35
35
|
Iso639["en"].alpha3_bibliographic # => "eng"
|
36
|
-
Iso639["en"].alpha3_terminology # =>
|
36
|
+
Iso639["en"].alpha3_terminology # => "eng"
|
37
37
|
Iso639["en"].name # => "English"
|
38
38
|
Iso639["en"].english_name # => "English"
|
39
39
|
Iso639["en"].french_name # => "anglais"
|
data/lib/iso639.rb
CHANGED
@@ -15,7 +15,7 @@ require "iso639/insensitive_hash"
|
|
15
15
|
# Iso639["en"].alpha2 # => "en"
|
16
16
|
# Iso639["en"].alpha3 # => "eng"
|
17
17
|
# Iso639["en"].alpha3_bibliographic # => "eng"
|
18
|
-
# Iso639["en"].alpha3_terminology # =>
|
18
|
+
# Iso639["en"].alpha3_terminology # => "eng"
|
19
19
|
# Iso639["en"].name # => "English"
|
20
20
|
# Iso639["en"].english_name # => "English"
|
21
21
|
# Iso639["en"].french_name # => "anglais"
|
data/lib/iso639/language.rb
CHANGED
@@ -8,31 +8,32 @@ module Iso639
|
|
8
8
|
# alpha3_bibliographic - A String representing the alpha-3 bibliographic code
|
9
9
|
# alpha3_terminology - A String representing the alpha-3 terminology code
|
10
10
|
# alpha2 - A String representing the alpha-2 code
|
11
|
-
#
|
12
|
-
#
|
13
|
-
def initialize(alpha3_bibliographic, alpha3_terminology, alpha2,
|
11
|
+
# english_names - A String representing the English names (semi-colon delimited)
|
12
|
+
# french_names - A String representing the French names (semi-colon delimited)
|
13
|
+
def initialize(alpha3_bibliographic, alpha3_terminology, alpha2, english_names, french_names)
|
14
14
|
@alpha3_bibliographic = strip_to_nil(alpha3_bibliographic)
|
15
|
-
@alpha3_terminology = strip_to_nil(alpha3_terminology)
|
15
|
+
@alpha3_terminology = strip_to_nil(alpha3_terminology) || @alpha3_bibliographic
|
16
16
|
@alpha2 = strip_to_nil(alpha2)
|
17
|
-
@english_names =
|
18
|
-
@french_names =
|
17
|
+
@english_names = split_and_strip(english_names)
|
18
|
+
@french_names = split_and_strip(french_names)
|
19
19
|
end
|
20
20
|
|
21
21
|
def english_name
|
22
22
|
english_names.first
|
23
23
|
end
|
24
24
|
alias_method :name, :english_name
|
25
|
+
alias_method :to_s, :english_name
|
25
26
|
|
26
27
|
def french_name
|
27
28
|
french_names.first
|
28
29
|
end
|
29
30
|
|
30
|
-
def to_s
|
31
|
-
name
|
32
|
-
end
|
33
|
-
|
34
31
|
private
|
35
32
|
|
33
|
+
def split_and_strip(names)
|
34
|
+
names.split(/;\s*/).map { |n| strip_to_nil(n) }
|
35
|
+
end
|
36
|
+
|
36
37
|
def strip_to_nil(val)
|
37
38
|
val = val.strip if val
|
38
39
|
return val unless val.nil? || val.empty?
|
data/lib/iso639/version.rb
CHANGED
data/test/iso639_test.rb
CHANGED
@@ -36,10 +36,13 @@ describe Iso639::LanguagesByAlpha3Terminology do
|
|
36
36
|
assert_equal "German", Iso639::LanguagesByAlpha3Terminology["DEU"].name
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should return valid languages by alpha-3 terminology code when it matches the bibliographic" do
|
40
|
+
assert_equal "English", Iso639::LanguagesByAlpha3Terminology["eng"].name
|
41
|
+
end
|
42
|
+
|
39
43
|
it "should return nil for unknown codes" do
|
40
44
|
assert_nil Iso639::LanguagesByAlpha3Terminology["xxx"]
|
41
45
|
assert_nil Iso639::LanguagesByAlpha3Terminology["en"]
|
42
|
-
assert_nil Iso639::LanguagesByAlpha3Terminology["eng"]
|
43
46
|
assert_nil Iso639::LanguagesByAlpha3Terminology["English"]
|
44
47
|
end
|
45
48
|
end
|
data/test/language_test.rb
CHANGED
@@ -33,6 +33,12 @@ describe Iso639::Language do
|
|
33
33
|
assert_nil lang.french_name
|
34
34
|
end
|
35
35
|
|
36
|
+
it "should assign bibliographic value to terminology if no terminolgy value" do
|
37
|
+
lang = Iso639::Language.new "eng", "", "en", "English", "anglais"
|
38
|
+
assert_equal "eng", lang.alpha3_bibliographic
|
39
|
+
assert_equal "eng", lang.alpha3_terminology
|
40
|
+
end
|
41
|
+
|
36
42
|
it "should return english name for #to_s" do
|
37
43
|
lang = Iso639::Language.new "", "", "", "English", ""
|
38
44
|
assert_equal "English", lang.to_s
|
metadata
CHANGED
@@ -2,47 +2,47 @@
|
|
2
2
|
name: iso639
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0
|
5
|
+
version: 1.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan McGeary
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
version_requirements: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4.3'
|
20
|
-
none: false
|
21
15
|
name: minitest
|
22
16
|
type: :development
|
23
|
-
prerelease: false
|
24
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
25
19
|
requirements:
|
26
20
|
- - ~>
|
27
21
|
- !ruby/object:Gem::Version
|
28
22
|
version: '4.3'
|
29
|
-
|
30
|
-
- !ruby/object:Gem::Dependency
|
23
|
+
prerelease: false
|
31
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
32
26
|
requirements:
|
33
27
|
- - ~>
|
34
28
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
36
|
-
|
29
|
+
version: '4.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
37
31
|
name: rake
|
38
32
|
type: :development
|
39
|
-
prerelease: false
|
40
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
41
35
|
requirements:
|
42
36
|
- - ~>
|
43
37
|
- !ruby/object:Gem::Version
|
44
38
|
version: '10.0'
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
41
|
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '10.0'
|
46
46
|
description: ISO 639-1 and ISO 639-2 lookups by name, alpha-2 code, or alpha-3 code
|
47
47
|
email:
|
48
48
|
- ryan@mcgeary.org
|
@@ -73,17 +73,17 @@ rdoc_options: []
|
|
73
73
|
require_paths:
|
74
74
|
- lib
|
75
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
76
77
|
requirements:
|
77
78
|
- - ! '>='
|
78
79
|
- !ruby/object:Gem::Version
|
79
80
|
version: '0'
|
80
|
-
none: false
|
81
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
82
83
|
requirements:
|
83
84
|
- - ! '>='
|
84
85
|
- !ruby/object:Gem::Version
|
85
86
|
version: '0'
|
86
|
-
none: false
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
89
|
rubygems_version: 1.8.23
|