iso-639 0.2.6 → 0.2.7

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
  SHA1:
3
- metadata.gz: 0263cfd7186c66c99ef204cae8d806be734572e4
4
- data.tar.gz: 1a63d2d476333d43a3c33bd370bbfcb602a97eec
3
+ metadata.gz: e04d56e8d3bcac20d583427975e5dc725d709bf0
4
+ data.tar.gz: ea2dbf57ea549df0407e4910d35ece88ab2241db
5
5
  SHA512:
6
- metadata.gz: 654bb7a95891255fbdff11d2bb3c18972010f7f7db152868c562400c53df56f91f66529e744157bec811abcfcb1ab835658fc657cfd7927b47d2b6f0bd1ed976
7
- data.tar.gz: 026f9abed71f92bfdaf89a73a4f930e26f755d5f29b07553b55dd732a6de71298fc68f3b22cef910a88095ef7eac7fa6225659292c09e22d089fce692d8a5e39
6
+ metadata.gz: d9660ca78c6c1c1370c4ddcd1c082e57e264c6ab069c7081140926cd98471e4b9b0e44081937bb8bd60b3233042790fb8036808d8b6fbaf3368659d41f2e1327
7
+ data.tar.gz: c41187fec4236013908099b83cee65f1b5ca78423e4d1d92c994c14a512f0af6c644e1ba9fd414f3e72115e8c9361e13a83ffeb80da820f1e9e40fb31937546f
data/.document CHANGED
@@ -1,4 +1,4 @@
1
- README.markdown
1
+ README.md
2
2
  lib/**/*.rb
3
3
  bin/*
4
4
  features/**/*.feature
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development, :test do
9
+ gem "allocation_stats"
9
10
  gem "minitest"
10
11
  gem "mocha"
11
12
  gem "rake"
@@ -1,18 +1,19 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- ast (2.2.0)
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.4)
8
+ minitest (5.9.0)
8
9
  mocha (1.1.0)
9
10
  metaclass (~> 0.0.1)
10
- parser (2.3.1.0)
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.1.2)
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.0)
25
- test-unit (3.1.8)
25
+ ruby-progressbar (1.8.1)
26
+ test-unit (3.2.0)
26
27
  power_assert
27
- unicode-display_width (1.0.5)
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
- gem install iso-639
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
- require 'iso-639'
17
+ ```ruby
18
+ require 'iso-639'
19
+ ```
16
20
 
17
21
  To find a language entry:
18
22
 
19
- # by alpha-2 or alpha-3 code
20
- ISO_639.find_by_code("en")
21
- # or
22
- ISO_639.find("en")
23
- # by English name
24
- ISO_639.find_by_english_name("Russian")
25
- # by French name
26
- ISO_639.find_by_french_name("français")
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
- ISO_639.search("spanish")
33
- # => [["spa", "", "es", "Spanish; Castilian", "espagnol; castillan"]]
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
- @entry = ISO_639.find("slo")
38
- # => ["slo", "slk", "sk", "Slovak", "slovaque"]
39
- @entry.alpha3_bibliographic
40
- # => "slo"
41
- @entry.alpha3 # shortcut for #alpha3_bibliographic
42
- # => "slo"
43
- @entry.alpha3_terminologic
44
- # => "slk"
45
- @entry.alpha2
46
- # => "sk"
47
- @entry.english_name
48
- # => "Slovak"
49
- @entry.french_name
50
- # => "slovaque"
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
 
@@ -5,23 +5,23 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "iso-639"
8
- s.version = "0.2.6"
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-05-09"
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.markdown"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  "Gemfile",
22
22
  "Gemfile.lock",
23
23
  "LICENSE",
24
- "README.markdown",
24
+ "README.md",
25
25
  "Rakefile",
26
26
  "iso-639.gemspec",
27
27
  "lib/iso-639.rb",
@@ -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
@@ -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.6
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-05-09 00:00:00.000000000 Z
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.markdown
89
+ - README.md
90
90
  files:
91
91
  - ".document"
92
92
  - Gemfile
93
93
  - Gemfile.lock
94
94
  - LICENSE
95
- - README.markdown
95
+ - README.md
96
96
  - Rakefile
97
97
  - iso-639.gemspec
98
98
  - lib/iso-639.rb