iso-639 0.3.5 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +36 -21
- data/README.md +4 -0
- data/iso-639.gemspec +2 -1
- data/lib/iso-639.rb +15 -5
- data/test/helper.rb +2 -0
- data/test/test_iso_639.rb +14 -4
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82638293b2ce0ad805527d4c94332dc4340f61dedc06c80d55f2db9edc3e97c8
|
4
|
+
data.tar.gz: 3aba44af194937d816337f6a53dbbfbf58cfcd8ec4845ca23443c42a500f0497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcaddf82f8af9ac2f1f207b538bfcd5167ab960754e28f39f368f7e582357d0f3501e31bcfb884a5fbb4baf5e4d10ea17eedb44b353c4bffe30f62e4865aee27
|
7
|
+
data.tar.gz: 22d0c99651c464c79a69105e7c0012124d8a0d7b5456459008852ce52ed0ee0d3a4d59dba2984ef88c6e1376807cddf3a42bc9b183dda06bf0a6c7527517a272
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,36 +2,51 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
allocation_stats (0.1.5)
|
5
|
-
ast (2.4.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
ast (2.4.2)
|
6
|
+
csv (3.3.0)
|
7
|
+
json (2.7.2)
|
8
|
+
language_server-protocol (3.17.0.3)
|
9
|
+
minitest (5.25.1)
|
10
|
+
mocha (2.4.5)
|
11
|
+
ruby2_keywords (>= 0.0.5)
|
12
|
+
parallel (1.26.3)
|
13
|
+
parser (3.3.5.0)
|
14
|
+
ast (~> 2.4.1)
|
15
|
+
racc
|
16
|
+
power_assert (2.0.4)
|
17
|
+
psych (5.1.2)
|
18
|
+
stringio
|
19
|
+
racc (1.8.1)
|
20
|
+
rainbow (3.1.1)
|
21
|
+
rake (13.2.1)
|
22
|
+
rdoc (6.7.0)
|
23
|
+
psych (>= 4.0.0)
|
24
|
+
regexp_parser (2.9.2)
|
25
|
+
rubocop (1.66.1)
|
26
|
+
json (~> 2.3)
|
27
|
+
language_server-protocol (>= 3.17.0)
|
19
28
|
parallel (~> 1.10)
|
20
|
-
parser (>=
|
29
|
+
parser (>= 3.3.0.2)
|
21
30
|
rainbow (>= 2.2.2, < 4.0)
|
22
|
-
|
31
|
+
regexp_parser (>= 2.4, < 3.0)
|
32
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
23
33
|
ruby-progressbar (~> 1.7)
|
24
|
-
unicode-display_width (>=
|
25
|
-
|
26
|
-
|
34
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
35
|
+
rubocop-ast (1.32.3)
|
36
|
+
parser (>= 3.3.1.0)
|
37
|
+
ruby-progressbar (1.13.0)
|
38
|
+
ruby2_keywords (0.0.5)
|
39
|
+
stringio (3.1.1)
|
40
|
+
test-unit (3.6.2)
|
27
41
|
power_assert
|
28
|
-
unicode-display_width (
|
42
|
+
unicode-display_width (2.6.0)
|
29
43
|
|
30
44
|
PLATFORMS
|
31
45
|
ruby
|
32
46
|
|
33
47
|
DEPENDENCIES
|
34
48
|
allocation_stats
|
49
|
+
csv
|
35
50
|
minitest
|
36
51
|
mocha
|
37
52
|
rake
|
@@ -40,4 +55,4 @@ DEPENDENCIES
|
|
40
55
|
test-unit
|
41
56
|
|
42
57
|
BUNDLED WITH
|
43
|
-
2.
|
58
|
+
2.2.28
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# ISO 639
|
2
2
|
|
3
|
+
[![Build Status](https://img.shields.io/github/actions/workflow/status/xwmx/iso-639/tests.yml?branch=master)](https://github.com/xwmx/iso-639/actions)
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/iso-639?color=blue)](http://rubygems.org/gems/iso-639)
|
5
|
+
[![Gem Downloads](https://img.shields.io/gem/dt/iso-639)](http://rubygems.org/gems/iso-639)
|
6
|
+
|
3
7
|
A Ruby gem that provides the ISO 639-2 and ISO 639-1 data sets along with some
|
4
8
|
convenience methods for accessing different entries and entry fields. The data
|
5
9
|
comes from the
|
data/iso-639.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'iso-639'
|
5
|
-
s.version = '0.3.
|
5
|
+
s.version = '0.3.8'
|
6
6
|
s.licenses = ['MIT']
|
7
7
|
s.summary = 'ISO 639-1 and ISO 639-2 language code entries and convenience methods.'
|
8
8
|
s.description = 'ISO 639-1 and ISO 639-2 language code entries and convenience methods.'
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
]
|
28
28
|
s.homepage = 'http://github.com/xwmx/iso-639'
|
29
29
|
s.require_paths = ['lib']
|
30
|
+
s.add_dependency('csv')
|
30
31
|
s.add_development_dependency('minitest', '~> 5', '>= 0')
|
31
32
|
s.add_development_dependency('mocha', '~> 1', '>= 0')
|
32
33
|
s.add_development_dependency('rdoc', '~> 6', '>= 0')
|
data/lib/iso-639.rb
CHANGED
@@ -16,6 +16,7 @@ class ISO_639 < Array
|
|
16
16
|
# https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
|
17
17
|
ISO_639_2 = lambda do
|
18
18
|
dataset = []
|
19
|
+
|
19
20
|
File.open(
|
20
21
|
File.join(File.dirname(__FILE__), 'data', 'ISO-639-2_utf-8.txt'),
|
21
22
|
'r:bom|utf-8'
|
@@ -24,29 +25,34 @@ class ISO_639 < Array
|
|
24
25
|
dataset << self[*row.map { |v| v || '' }].freeze
|
25
26
|
end
|
26
27
|
end
|
27
|
-
|
28
|
+
|
29
|
+
dataset
|
28
30
|
end.call.freeze
|
29
31
|
|
30
32
|
# An inverted index generated from the ISO_639_2 data. Used for searching
|
31
33
|
# all words and codes in all fields.
|
32
34
|
INVERTED_INDEX = lambda do
|
33
35
|
index = {}
|
36
|
+
|
34
37
|
ISO_639_2.each_with_index do |record, i|
|
35
38
|
record.each do |field|
|
36
39
|
downcased = field.downcase
|
40
|
+
|
37
41
|
words = (
|
38
42
|
downcased.split(/[[:blank:]]|\(|\)|,|;/) +
|
39
43
|
downcased.split(/;/)
|
40
44
|
)
|
45
|
+
|
41
46
|
words.each do |word|
|
42
47
|
unless word.empty?
|
43
48
|
index[word] ||= []
|
44
|
-
index[word] <<
|
49
|
+
index[word] << i
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
end
|
49
|
-
|
54
|
+
|
55
|
+
index
|
50
56
|
end.call.freeze
|
51
57
|
|
52
58
|
# The ISO 639-1 dataset as an array of entries. Each entry is an array with
|
@@ -66,7 +72,7 @@ class ISO_639 < Array
|
|
66
72
|
return if code.nil?
|
67
73
|
|
68
74
|
case code.length
|
69
|
-
when 3
|
75
|
+
when 3, 7
|
70
76
|
ISO_639_2.detect do |entry|
|
71
77
|
entry if [entry.alpha3, entry.alpha3_terminologic].include?(code)
|
72
78
|
end
|
@@ -76,6 +82,7 @@ class ISO_639 < Array
|
|
76
82
|
end
|
77
83
|
end
|
78
84
|
end
|
85
|
+
|
79
86
|
alias_method :find, :find_by_code
|
80
87
|
|
81
88
|
# Returns the entry array for a language specified by its English name.
|
@@ -96,9 +103,11 @@ class ISO_639 < Array
|
|
96
103
|
# of any kind, or it can be one of the words contained in the English or
|
97
104
|
# French name field.
|
98
105
|
def search(term)
|
99
|
-
term
|
106
|
+
term ||= ''
|
107
|
+
|
100
108
|
normalized_term = term.downcase.strip
|
101
109
|
indexes = INVERTED_INDEX[normalized_term]
|
110
|
+
|
102
111
|
indexes ? ISO_639_2.values_at(*indexes).uniq : []
|
103
112
|
end
|
104
113
|
end
|
@@ -107,6 +116,7 @@ class ISO_639 < Array
|
|
107
116
|
def alpha3_bibliographic
|
108
117
|
self[0]
|
109
118
|
end
|
119
|
+
|
110
120
|
alias_method :alpha3, :alpha3_bibliographic
|
111
121
|
|
112
122
|
# The entry's alpha-3 terminologic (when given)
|
data/test/helper.rb
CHANGED
@@ -7,6 +7,7 @@ begin
|
|
7
7
|
rescue Bundler::BundlerError => e
|
8
8
|
warn e.message
|
9
9
|
warn 'Run `bundle install` to install missing gems'
|
10
|
+
|
10
11
|
exit e.status_code
|
11
12
|
end
|
12
13
|
require 'minitest/autorun'
|
@@ -15,4 +16,5 @@ require 'mocha/minitest'
|
|
15
16
|
|
16
17
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
18
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
18
20
|
require 'iso-639'
|
data/test/test_iso_639.rb
CHANGED
@@ -12,11 +12,11 @@ describe ISO_639 do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should return nil find_by_code when code does not exist or is invalid' do
|
15
|
-
assert ISO_639.find_by_code(nil).nil?,
|
16
|
-
assert ISO_639.find_by_code('xxx').nil?,
|
17
|
-
assert ISO_639.find_by_code('xx').nil?,
|
15
|
+
assert ISO_639.find_by_code(nil).nil?, 'nil code'
|
16
|
+
assert ISO_639.find_by_code('xxx').nil?, 'xxx alfa-3 not existing code'
|
17
|
+
assert ISO_639.find_by_code('xx').nil?, 'xx alfa-2 not existing code'
|
18
18
|
assert ISO_639.find_by_code('xxxx').nil?, 'xxxx lengthy code'
|
19
|
-
assert ISO_639.find_by_code('').nil?,
|
19
|
+
assert ISO_639.find_by_code('').nil?, 'empty string code'
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should return entry for alpha-2 code' do
|
@@ -24,6 +24,15 @@ describe ISO_639 do
|
|
24
24
|
assert_equal ['eng', '', 'en', 'English', 'anglais'], ISO_639.find('en')
|
25
25
|
end
|
26
26
|
|
27
|
+
it 'should return entry for alpha-3 bibliographic code' do
|
28
|
+
assert_equal %w[ger deu de German allemand], ISO_639.find('ger')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should return entry for 7-character alpha-3 terminologic code (qaa-qtz)' do
|
32
|
+
assert_equal ['qaa-qtz', '', '', 'Reserved for local use', "réservée à l'usage local"], ISO_639.find_by_code('qaa-qtz')
|
33
|
+
assert_equal ['qaa-qtz', '', '', 'Reserved for local use', "réservée à l'usage local"], ISO_639.find('qaa-qtz')
|
34
|
+
end
|
35
|
+
|
27
36
|
it 'should return entry for alpha-3 terminologic code' do
|
28
37
|
assert_equal %w[ger deu de German allemand], ISO_639.find('deu')
|
29
38
|
end
|
@@ -46,6 +55,7 @@ describe ISO_639 do
|
|
46
55
|
].each_with_index do |m, i|
|
47
56
|
it "should respond to and return #{m}" do
|
48
57
|
@entry = ISO_639.find('en')
|
58
|
+
|
49
59
|
assert @entry.respond_to?(m)
|
50
60
|
assert_equal ['eng', 'eng', '', 'en', 'English', 'anglais'][i], @entry.send(m)
|
51
61
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iso-639
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Melody
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: csv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,7 +147,7 @@ homepage: http://github.com/xwmx/iso-639
|
|
133
147
|
licenses:
|
134
148
|
- MIT
|
135
149
|
metadata: {}
|
136
|
-
post_install_message:
|
150
|
+
post_install_message:
|
137
151
|
rdoc_options: []
|
138
152
|
require_paths:
|
139
153
|
- lib
|
@@ -148,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
162
|
- !ruby/object:Gem::Version
|
149
163
|
version: '0'
|
150
164
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
152
|
-
signing_key:
|
165
|
+
rubygems_version: 3.5.3
|
166
|
+
signing_key:
|
153
167
|
specification_version: 4
|
154
168
|
summary: ISO 639-1 and ISO 639-2 language code entries and convenience methods.
|
155
169
|
test_files: []
|