iso-639 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.document +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -7
- data/{README.markdown → README.md} +36 -26
- data/iso-639.gemspec +4 -4
- data/lib/iso-639.rb +16 -3
- data/test/test_iso_639.rb +36 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e04d56e8d3bcac20d583427975e5dc725d709bf0
|
4
|
+
data.tar.gz: ea2dbf57ea549df0407e4910d35ece88ab2241db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9660ca78c6c1c1370c4ddcd1c082e57e264c6ab069c7081140926cd98471e4b9b0e44081937bb8bd60b3233042790fb8036808d8b6fbaf3368659d41f2e1327
|
7
|
+
data.tar.gz: c41187fec4236013908099b83cee65f1b5ca78423e4d1d92c994c14a512f0af6c644e1ba9fd414f3e72115e8c9361e13a83ffeb80da820f1e9e40fb31937546f
|
data/.document
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
4
|
+
allocation_stats (0.1.5)
|
5
|
+
ast (2.3.0)
|
5
6
|
json (1.8.3)
|
6
7
|
metaclass (0.0.4)
|
7
|
-
minitest (5.
|
8
|
+
minitest (5.9.0)
|
8
9
|
mocha (1.1.0)
|
9
10
|
metaclass (~> 0.0.1)
|
10
|
-
parser (2.3.1.
|
11
|
+
parser (2.3.1.2)
|
11
12
|
ast (~> 2.2)
|
12
13
|
power_assert (0.3.0)
|
13
14
|
powerpack (0.1.1)
|
14
15
|
rainbow (2.1.0)
|
15
|
-
rake (11.
|
16
|
+
rake (11.2.2)
|
16
17
|
rdoc (4.2.2)
|
17
18
|
json (~> 1.4)
|
18
19
|
rubocop (0.40.0)
|
@@ -21,15 +22,16 @@ GEM
|
|
21
22
|
rainbow (>= 1.99.1, < 3.0)
|
22
23
|
ruby-progressbar (~> 1.7)
|
23
24
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
24
|
-
ruby-progressbar (1.8.
|
25
|
-
test-unit (3.
|
25
|
+
ruby-progressbar (1.8.1)
|
26
|
+
test-unit (3.2.0)
|
26
27
|
power_assert
|
27
|
-
unicode-display_width (1.0
|
28
|
+
unicode-display_width (1.1.0)
|
28
29
|
|
29
30
|
PLATFORMS
|
30
31
|
ruby
|
31
32
|
|
32
33
|
DEPENDENCIES
|
34
|
+
allocation_stats
|
33
35
|
minitest
|
34
36
|
mocha
|
35
37
|
rake
|
@@ -4,7 +4,9 @@ A Ruby gem that provides the ISO 639-2 and ISO 639-1 data sets along with some c
|
|
4
4
|
|
5
5
|
To install:
|
6
6
|
|
7
|
-
|
7
|
+
```bash
|
8
|
+
gem install iso-639
|
9
|
+
```
|
8
10
|
|
9
11
|
The [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) specification uses a two-letter code to identify a language and is often the recommended way to identify languages in computer applications. The ISO 639-1 specification covers most developed and widely used languages.
|
10
12
|
|
@@ -12,42 +14,50 @@ The [ISO 639-2](http://www.loc.gov/standards/iso639-2/) ([Wikipedia](http://en.w
|
|
12
14
|
|
13
15
|
## Usage
|
14
16
|
|
15
|
-
|
17
|
+
```ruby
|
18
|
+
require 'iso-639'
|
19
|
+
```
|
16
20
|
|
17
21
|
To find a language entry:
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
```ruby
|
24
|
+
# by alpha-2 or alpha-3 code
|
25
|
+
ISO_639.find_by_code("en")
|
26
|
+
# or
|
27
|
+
ISO_639.find("en")
|
28
|
+
# by English name
|
29
|
+
ISO_639.find_by_english_name("Russian")
|
30
|
+
# by French name
|
31
|
+
ISO_639.find_by_french_name("français")
|
32
|
+
```
|
27
33
|
|
28
34
|
The `ISO_639.search` class method searches across all fields and will
|
29
35
|
match names in cases where a record has multiple names. This method
|
30
36
|
always returns an array of 0 or more results. For example:
|
31
37
|
|
32
|
-
|
33
|
-
|
38
|
+
```ruby
|
39
|
+
ISO_639.search("spanish")
|
40
|
+
# => [["spa", "", "es", "Spanish; Castilian", "espagnol; castillan"]]
|
41
|
+
```
|
34
42
|
|
35
43
|
Entries are arrays with convenience methods for accessing fields:
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
```ruby
|
46
|
+
@entry = ISO_639.find("slo")
|
47
|
+
# => ["slo", "slk", "sk", "Slovak", "slovaque"]
|
48
|
+
@entry.alpha3_bibliographic
|
49
|
+
# => "slo"
|
50
|
+
@entry.alpha3 # shortcut for #alpha3_bibliographic
|
51
|
+
# => "slo"
|
52
|
+
@entry.alpha3_terminologic
|
53
|
+
# => "slk"
|
54
|
+
@entry.alpha2
|
55
|
+
# => "sk"
|
56
|
+
@entry.english_name
|
57
|
+
# => "Slovak"
|
58
|
+
@entry.french_name
|
59
|
+
# => "slovaque"
|
60
|
+
```
|
51
61
|
|
52
62
|
The full data set is available through the `ISO_639::ISO_639_1` and `ISO_639::ISO_639_2` constants.
|
53
63
|
|
data/iso-639.gemspec
CHANGED
@@ -5,23 +5,23 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "iso-639"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["William Melody"]
|
12
|
-
s.date = "2016-
|
12
|
+
s.date = "2016-06-22"
|
13
13
|
s.description = "ISO 639-1 and ISO 639-2 language code entries and convenience methods"
|
14
14
|
s.email = "hi@williammelody.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
"Gemfile",
|
22
22
|
"Gemfile.lock",
|
23
23
|
"LICENSE",
|
24
|
-
"README.
|
24
|
+
"README.md",
|
25
25
|
"Rakefile",
|
26
26
|
"iso-639.gemspec",
|
27
27
|
"lib/iso-639.rb",
|
data/lib/iso-639.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
# http://www.loc.gov/standards/iso639-2/ascii_8bits.html
|
3
4
|
|
4
5
|
class ISO_639 < Array
|
6
|
+
# Redefine `[]` to freeze all strings and arrays.
|
7
|
+
#
|
8
|
+
# Ruby 2.3+ uses the `frozen_string_literal` magic comment to freeze all
|
9
|
+
# strings, while previous versions require the `#map` approach.
|
10
|
+
def self.[](*args)
|
11
|
+
if args[0].frozen?
|
12
|
+
super(*args).freeze
|
13
|
+
else
|
14
|
+
super(*args.map(&:freeze)).freeze
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
5
18
|
# The ISO 639-2 dataset as an array of entries. Each entry is an array with
|
6
19
|
# the following format:
|
7
20
|
# * [0]: an alpha-3 (bibliographic) code
|
@@ -495,7 +508,7 @@ class ISO_639 < Array
|
|
495
508
|
self["zun", "", "", "Zuni", "zuni"],
|
496
509
|
self["zxx", "", "", "No linguistic content; Not applicable", "pas de contenu linguistique; non applicable"],
|
497
510
|
self["zza", "", "", "Zaza; Dimili; Dimli; Kirdki; Kirmanjki; Zazaki", "zaza; dimili; dimli; kirdki; kirmanjki; zazaki"]
|
498
|
-
]
|
511
|
+
].freeze
|
499
512
|
|
500
513
|
# An inverted index generated from the ISO_639_2 data. Used for searching
|
501
514
|
# all words and codes in all fields.
|
@@ -517,7 +530,7 @@ class ISO_639 < Array
|
|
517
530
|
end
|
518
531
|
end
|
519
532
|
return index
|
520
|
-
end.call
|
533
|
+
end.call.freeze
|
521
534
|
|
522
535
|
# The ISO 639-1 dataset as an array of entries. Each entry is an array with
|
523
536
|
# the following format:
|
@@ -528,7 +541,7 @@ class ISO_639 < Array
|
|
528
541
|
# * [4]: a French name
|
529
542
|
ISO_639_1 = ISO_639_2.collect do |entry|
|
530
543
|
entry unless entry[2].empty?
|
531
|
-
end.compact
|
544
|
+
end.compact.freeze
|
532
545
|
|
533
546
|
class << self
|
534
547
|
# Returns the entry array for an alpha-2 or alpha-3 code
|
data/test/test_iso_639.rb
CHANGED
@@ -90,4 +90,40 @@ describe ISO_639 do
|
|
90
90
|
ISO_639.search("yupik, langues")
|
91
91
|
)
|
92
92
|
end
|
93
|
+
|
94
|
+
it "should error when attempting to change immutable ISO_639_2" do
|
95
|
+
assert_raises RuntimeError do
|
96
|
+
ISO_639::ISO_639_2 << ["test", "array"]
|
97
|
+
end
|
98
|
+
|
99
|
+
assert_raises RuntimeError do
|
100
|
+
ISO_639::ISO_639_2[0] = []
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_raises RuntimeError do
|
104
|
+
ISO_639::ISO_639_2[0][1] = ""
|
105
|
+
end
|
106
|
+
|
107
|
+
assert_raises RuntimeError do
|
108
|
+
ISO_639::ISO_639_2[0][1].upcase!
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should error when attempting to change immutable ISO_639_1" do
|
113
|
+
assert_raises RuntimeError do
|
114
|
+
ISO_639::ISO_639_1 << ["test", "array"]
|
115
|
+
end
|
116
|
+
|
117
|
+
assert_raises RuntimeError do
|
118
|
+
ISO_639::ISO_639_1[0] = []
|
119
|
+
end
|
120
|
+
|
121
|
+
assert_raises RuntimeError do
|
122
|
+
ISO_639::ISO_639_1[0][1] = ""
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_raises RuntimeError do
|
126
|
+
ISO_639::ISO_639_1[0][1].upcase!
|
127
|
+
end
|
128
|
+
end
|
93
129
|
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.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Melody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -86,13 +86,13 @@ executables: []
|
|
86
86
|
extensions: []
|
87
87
|
extra_rdoc_files:
|
88
88
|
- LICENSE
|
89
|
-
- README.
|
89
|
+
- README.md
|
90
90
|
files:
|
91
91
|
- ".document"
|
92
92
|
- Gemfile
|
93
93
|
- Gemfile.lock
|
94
94
|
- LICENSE
|
95
|
-
- README.
|
95
|
+
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- iso-639.gemspec
|
98
98
|
- lib/iso-639.rb
|