iso-639 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 504e2b6dab9b710bb70fb319bd734397c2e088addc75a11e2948350e51dac6f1
4
- data.tar.gz: b508045598ebf54e2cd347b8230d7a59e613ce90e839e5b89ca659ac278d6b51
3
+ metadata.gz: 3c009734c8c8f89dcc8ab479124f1c274b854e926a3aab219d9548ff08ca4fe3
4
+ data.tar.gz: 7ebdb1a4c925a1eb0a58df46a50f5fce5c629a385fa6fcb8b8d189eb7d312641
5
5
  SHA512:
6
- metadata.gz: d960c2d65b684cdd0ab904fabaecdb85e5feab58ec8f1047f2d0c076f17742f67d18a40cf87a269805b12209b4b6fa02efb3ad007db448da6a97ebf3462e8d29
7
- data.tar.gz: c5cfeed25b18c74e605b5814956f84bab3325d1dba63a3bae86981aafa2390bbc58c00638f88200eeff56c55530bc8094fc61a696af3c7721cf35fd1e2c05d46
6
+ metadata.gz: 520ba2092a5df4d0f67621f685df720a5cade3760e90a16e445ffff9fe3ed8105e1837e2fec9af500818ccafb2db4721cc81cea89fbf0d5a12343192162a4ad6
7
+ data.tar.gz: e3c55fc6423fe290f205924a779400b45394a067a38c75390209e64384d75a8e1ec5c053499d65fae9a541c37a6ccdfc33fbee38a097b3b6db7bb28f1fd0cf7f
data/Gemfile.lock CHANGED
@@ -2,30 +2,33 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  allocation_stats (0.1.5)
5
- ast (2.4.0)
6
- jaro_winkler (1.5.4)
7
- minitest (5.14.0)
8
- mocha (1.11.2)
9
- parallel (1.19.1)
10
- parser (2.7.0.3)
11
- ast (~> 2.4.0)
12
- power_assert (1.1.6)
5
+ ast (2.4.2)
6
+ minitest (5.14.4)
7
+ mocha (1.13.0)
8
+ parallel (1.21.0)
9
+ parser (3.0.2.0)
10
+ ast (~> 2.4.1)
11
+ power_assert (2.0.1)
13
12
  rainbow (3.0.0)
14
- rake (13.0.1)
15
- rdoc (6.2.1)
16
- rexml (3.2.4)
17
- rubocop (0.80.1)
18
- jaro_winkler (~> 1.5.1)
13
+ rake (13.0.6)
14
+ rdoc (6.3.3)
15
+ regexp_parser (2.1.1)
16
+ rexml (3.2.5)
17
+ rubocop (1.22.3)
19
18
  parallel (~> 1.10)
20
- parser (>= 2.7.0.1)
19
+ parser (>= 3.0.0.0)
21
20
  rainbow (>= 2.2.2, < 4.0)
21
+ regexp_parser (>= 1.8, < 3.0)
22
22
  rexml
23
+ rubocop-ast (>= 1.12.0, < 2.0)
23
24
  ruby-progressbar (~> 1.7)
24
- unicode-display_width (>= 1.4.0, < 1.7)
25
- ruby-progressbar (1.10.1)
26
- test-unit (3.3.5)
25
+ unicode-display_width (>= 1.4.0, < 3.0)
26
+ rubocop-ast (1.13.0)
27
+ parser (>= 3.0.1.1)
28
+ ruby-progressbar (1.11.0)
29
+ test-unit (3.5.1)
27
30
  power_assert
28
- unicode-display_width (1.6.1)
31
+ unicode-display_width (2.1.0)
29
32
 
30
33
  PLATFORMS
31
34
  ruby
@@ -40,4 +43,4 @@ DEPENDENCIES
40
43
  test-unit
41
44
 
42
45
  BUNDLED WITH
43
- 2.1.4
46
+ 2.2.28
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ISO 639
2
2
 
3
+ [![Build Status](https://travis-ci.org/xwmx/iso-639.svg?branch=master)](https://travis-ci.org/xwmx/iso-639)
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'
5
+ s.version = '0.3.6'
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.'
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,6 +25,7 @@ class ISO_639 < Array
24
25
  dataset << self[*row.map { |v| v || '' }].freeze
25
26
  end
26
27
  end
28
+
27
29
  return dataset
28
30
  end.call.freeze
29
31
 
@@ -31,21 +33,25 @@ class ISO_639 < Array
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] << i
49
+ index[word] << i
45
50
  end
46
51
  end
47
52
  end
48
53
  end
54
+
49
55
  return index
50
56
  end.call.freeze
51
57
 
@@ -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?, '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'
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?, 'empty string code'
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso-639
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
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: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2022-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -133,7 +133,7 @@ homepage: http://github.com/xwmx/iso-639
133
133
  licenses:
134
134
  - MIT
135
135
  metadata: {}
136
- post_install_message:
136
+ post_install_message:
137
137
  rdoc_options: []
138
138
  require_paths:
139
139
  - lib
@@ -148,8 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
- rubygems_version: 3.1.2
152
- signing_key:
151
+ rubygems_version: 3.2.22
152
+ signing_key:
153
153
  specification_version: 4
154
154
  summary: ISO 639-1 and ISO 639-2 language code entries and convenience methods.
155
155
  test_files: []