lcclasses 0.1.1 → 0.2.0

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
- SHA1:
3
- metadata.gz: 21d2c58127f8da9ef898fd8275f38adfd604360e
4
- data.tar.gz: 64293c868662809bacdd5c684c024abfbced8da0
2
+ SHA256:
3
+ metadata.gz: 49b2f5106b678c366efacf049369567d895f1e9869db97cdd476b06b02791adb
4
+ data.tar.gz: 8e5ac470b862993e636db8a97980b83e4773f6fdc3ce4af3bf0b8285291ef840
5
5
  SHA512:
6
- metadata.gz: 91fd6596c61564b6749541e121e181d455b21a44c018c9dc1c41e639e22470c449e856bc8e8d879b10e61247bc3b05dbeb3c67e983514a1c8e115e4b29e79b53
7
- data.tar.gz: 5d42ba82d6669f80a8f21ad35554a6e5d6f0eb8c6510367ddeecdeec34451333691997209138d786acf6547a8aec5386d24456269c3ffbed429ed611ac5c746a
6
+ metadata.gz: fa3770b6bb17e9002932fccd05eb5154fa4a2b8b79c60c47adf42a5484280021753a41da01a07612fed8257670f60863fc336a9afee384bc5cfd9b318f04e9ec
7
+ data.tar.gz: bdcda9e0a43f8e36257d16b2b5434eb5a6416eaeda132d7172f32c9a1f238ba9b171ac10df807b5ba3b9bcac062eb9bf01f9e953a6e9800154994315a3eccc6e
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/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # LCCLasses
2
+
3
+ A Ruby gem that provides the Library of Congress Classification system main classes and subclasses along with some convenience methods.
4
+
5
+ To install:
6
+
7
+ ```bash
8
+ gem install lcclasses
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ To find a classification code:
14
+
15
+ ```ruby
16
+ LCClasses.find_main_class_by_code("T")
17
+ => ["T", "Technology (General)"]
18
+ LCClasses.find_subclass_by_code("AM")
19
+ => ["AM", "Museums. Collectors and collecting"]
20
+ LCClasses.find_all_by_code("E")
21
+ => # returns the main "E" class and all subclasses in nested array
22
+ LCClasses.main_classes
23
+ => # returns all main classes
24
+ LCClasses.subclasses
25
+ => # returns all subclasses
26
+ ```
27
+
28
+ The entire set of classes can be retrieved in 3 formats:
29
+
30
+ ```ruby
31
+ LCClasses::CLASS_HASH
32
+ => # nested hash of classes and subclasses
33
+ LCClasses.nested
34
+ => # nested array of classes and subclasses as LCClasses::LCClass objects
35
+ LCClasses.flat
36
+ => # flat array of classes and subclasses as LCClasses::LCClass objects
37
+ ```
38
+
39
+ The `CLASS_HASH` constant is in the following format (truncated example):
40
+
41
+ ```ruby
42
+ { "A" => {
43
+ :name => "General Works",
44
+ :subclasses => {
45
+ "AC" => { :name => "Collections; Series; Collected works" }
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ Classes are returned as specialized LCClasses::Class arrays in the format `[code, name]`. In the case of nested LCClasses:LCClass objects, they are in the format `[main_class_code, main_class_name, [[subclass_code, subclass_name]]]`. These objects are normal arrays with the following methods added:
52
+
53
+ ```ruby
54
+ @class = LCClasses.find_main_class_by_code("M")
55
+ @class.code
56
+ => "M"
57
+ @class.name
58
+ => "Music"
59
+ @class.subclasses
60
+ => [["M", "Music"], ["ML", "Literature on music"], ["MT", "Instruction and study"]]
61
+ ```
62
+
63
+ ## Note on Patches/Pull Requests
64
+
65
+ * Fork the project.
66
+ * Make your feature addition or bug fix.
67
+ * Add tests for it. This is important so I don't break it in a
68
+ future version unintentionally.
69
+ * Commit, do not mess with rakefile, version, or history.
70
+ (if you want to have your own version, that is fine but
71
+ bump version in a commit by itself I can ignore when I pull)
72
+ * Send me a pull request. Bonus points for topic branches.
73
+
74
+ ## Copyright
75
+
76
+ Copyright (c) 2010 William Melody. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
5
  begin
6
6
  Bundler.setup(:default, :development)
7
7
  rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts 'Run `bundle install` to install missing gems'
8
+ warn e.message
9
+ warn 'Run `bundle install` to install missing gems'
10
10
  exit e.status_code
11
11
  end
12
12
  require 'rake'
data/lcclasses.gemspec CHANGED
@@ -1,55 +1,37 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
5
2
 
6
3
  Gem::Specification.new do |s|
7
- s.name = %q{lcclasses}
8
- s.version = '0.1.1'
9
-
10
- s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
4
+ s.name = 'lcclasses'
5
+ s.version = '0.2.0'
6
+ s.licenses = ['MIT']
7
+ s.summary = 'Library of Congress Classification classes and subclasses.'
8
+ s.description = 'Library of Congress Classification classes and subclasses.'
11
9
  s.authors = ['William Melody']
12
- s.date = %q{2016-05-09}
13
- s.description = %q{Library of Congress Classification classes and subclasses}
14
- s.email = %q{hi@williammelody.com}
10
+ s.email = 'hi@williammelody.com'
11
+ s.date = '2020-03-18'
15
12
  s.extra_rdoc_files = [
16
13
  'LICENSE',
17
- 'README.markdown'
14
+ 'README.md'
18
15
  ]
19
16
  s.files = [
20
17
  '.document',
21
- '.gitignore',
22
- 'LICENSE',
23
- 'README.markdown',
24
- 'Rakefile',
25
- 'lcclasses.gemspec',
26
- 'lib/lcclasses.rb',
27
- 'test/helper.rb',
28
- 'test/test_lcclasses.rb'
18
+ '.gitignore',
19
+ 'LICENSE',
20
+ 'README.md',
21
+ 'Rakefile',
22
+ 'lcclasses.gemspec',
23
+ 'lib/lcclasses.rb',
24
+ 'test/helper.rb',
25
+ 'test/test_lcclasses.rb'
29
26
  ]
30
- s.homepage = %q{http://github.com/alphabetum/lcclasses}
31
- s.licenses = ['MIT']
32
- s.rdoc_options = ['--charset=UTF-8']
33
- s.require_paths = ['lib']
34
- s.rubygems_version = %q{1.8.24}
35
- s.summary = %q{Library of Congress Classification classes and subclasses}
36
27
  s.test_files = [
37
28
  'test/helper.rb',
38
- 'test/test_lcclasses.rb'
29
+ 'test/test_lcclasses.rb'
39
30
  ]
40
-
41
- if s.respond_to? :specification_version then
42
- s.specification_version = 3
43
-
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_development_dependency(%q<minitest>, ['>= 0'])
46
- s.add_development_dependency(%q<rdoc>, ['>= 0'])
47
- else
48
- s.add_dependency(%q<minitest>, ['>= 0'])
49
- s.add_dependency(%q<rdoc>, ['>= 0'])
50
- end
51
- else
52
- s.add_dependency(%q<minitest>, ['>= 0'])
53
- s.add_dependency(%q<rdoc>, ['>= 0'])
54
- end
31
+ s.homepage = 'http://github.com/xwmx/lcclasses'
32
+ s.require_paths = ['lib']
33
+ s.add_development_dependency('minitest', '~> 5', '>= 0')
34
+ s.add_development_dependency('rdoc', '~> 6', '>= 0')
35
+ s.add_development_dependency('rubocop', '~> 0', '>= 0.49.0')
36
+ s.required_ruby_version = '>= 2.3'
55
37
  end
data/lib/lcclasses.rb CHANGED
@@ -1,30 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LCClasses
2
4
  class LCClass < Array
3
5
  # Convert nested LCClasses::CLASS_HASH to nested array.
4
6
  def self.nest(hash)
5
7
  return self[] if hash.nil?
8
+
6
9
  hash.sort { |a, b| a[0] <=> b[0] }.inject(self[]) do |result, klass|
7
- if klass[1][:subclasses]
8
- result << self[klass[0], klass[1][:name], self.nest(klass[1][:subclasses])]
9
- else
10
- result << self[klass[0], klass[1][:name]]
11
- end
10
+ result << if klass[1][:subclasses]
11
+ self[klass[0], klass[1][:name], self.nest(klass[1][:subclasses])]
12
+ else
13
+ self[klass[0], klass[1][:name]]
14
+ end
12
15
  end
13
16
  end
14
17
 
15
18
  # Convert nested LCClasses::CLASS_HASH to flat array.
16
19
  def self.flatten(hash)
17
20
  return self[] if hash.nil?
21
+
18
22
  hash.sort { |a, b| a[0] <=> b[0] }.inject(self[]) do |result, klass|
19
23
  result << self[klass[0], klass[1][:name]]
20
- result += self.flatten(klass[1][:subclasses])
24
+ result + self.flatten(klass[1][:subclasses])
21
25
  end
22
26
  end
23
27
 
24
28
  # Return the subclasses of this class, if any.
25
29
  def subclasses
26
- return unless i = LCClasses::CLASS_HASH[self[0]]
27
- LCClasses::LCClass.nest(i[:subclasses])
30
+ class_data = LCClasses::CLASS_HASH[self[0]]
31
+ return if class_data.nil? || class_data.empty?
32
+
33
+ LCClasses::LCClass.nest(class_data[:subclasses])
28
34
  end
29
35
 
30
36
  # The class code.
@@ -364,7 +370,7 @@ module LCClasses
364
370
  'ZA' => { :name => 'Information resources (General)' }
365
371
  }
366
372
  }
367
- }
373
+ }.freeze
368
374
 
369
375
  # An array of main LC Classes.
370
376
  def self.main_classes
@@ -376,7 +382,7 @@ module LCClasses
376
382
  # An array of all LC Subclasses.
377
383
  def self.subclasses
378
384
  self.main_classes.inject([]) do |result, main_class|
379
- result += main_class.subclasses
385
+ result + main_class.subclasses
380
386
  end
381
387
  end
382
388
 
@@ -406,7 +412,6 @@ module LCClasses
406
412
 
407
413
  # Find all main classes and subclass that match or start with a code or character.
408
414
  def self.find_all_by_code(code)
409
- LCClasses.flat.select { |i| i[0] if (i[0] =~ /^#{code}[A-Z]?[A-Z]?/) }
415
+ LCClasses.flat.select { |i| i[0] if i[0] =~ /^#{code}[A-Z]?[A-Z]?/ }
410
416
  end
411
-
412
417
  end
data/test/helper.rb CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler'
3
5
  begin
4
6
  Bundler.setup(:default, :development)
5
7
  rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts 'Run `bundle install` to install missing gems'
8
+ warn e.message
9
+ warn 'Run `bundle install` to install missing gems'
8
10
  exit e.status_code
9
11
  end
10
12
  require 'minitest/autorun'
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'helper'
2
4
 
3
5
  describe LCClasses do
4
-
5
6
  it 'should return main classes' do
6
7
  assert_equal 21, LCClasses.main_classes.length
7
8
  end
@@ -16,7 +17,7 @@ describe LCClasses do
16
17
 
17
18
  it 'should should return nested' do
18
19
  assert_equal 21, LCClasses.nested.length
19
- assert_equal 223, LCClasses.nested.inject([]) { |r, m| r += m.subclasses }.length
20
+ assert_equal 223, LCClasses.nested.inject([]) { |a, e| a + e.subclasses }.length
20
21
  end
21
22
 
22
23
  it 'should find main class or subclass by code' do
@@ -38,13 +39,12 @@ describe LCClasses do
38
39
  end
39
40
 
40
41
  describe LCClasses::LCClass do
41
-
42
42
  def setup
43
43
  @hash = {
44
44
  'A' => {
45
45
  :name => 'General Works',
46
46
  :subclasses => {
47
- 'AC' => { :name => 'Collections; Series; Collected works' }
47
+ 'AC' => { :name => 'Collections; Series; Collected works' }
48
48
  }
49
49
  }
50
50
  }
metadata CHANGED
@@ -1,19 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lcclasses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
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: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: '0'
@@ -21,6 +24,9 @@ dependencies:
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: '0'
@@ -28,6 +34,9 @@ dependencies:
28
34
  name: rdoc
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '6'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
42
  version: '0'
@@ -35,52 +44,72 @@ dependencies:
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '6'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rubocop
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
38
60
  - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.49.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
39
68
  - !ruby/object:Gem::Version
40
69
  version: '0'
41
- description: Library of Congress Classification classes and subclasses
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.49.0
73
+ description: Library of Congress Classification classes and subclasses.
42
74
  email: hi@williammelody.com
43
75
  executables: []
44
76
  extensions: []
45
77
  extra_rdoc_files:
46
78
  - LICENSE
47
- - README.markdown
79
+ - README.md
48
80
  files:
49
81
  - ".document"
50
82
  - ".gitignore"
51
83
  - LICENSE
52
- - README.markdown
84
+ - README.md
53
85
  - Rakefile
54
86
  - lcclasses.gemspec
55
87
  - lib/lcclasses.rb
56
88
  - test/helper.rb
57
89
  - test/test_lcclasses.rb
58
- homepage: http://github.com/alphabetum/lcclasses
90
+ homepage: http://github.com/xwmx/lcclasses
59
91
  licenses:
60
92
  - MIT
61
93
  metadata: {}
62
94
  post_install_message:
63
- rdoc_options:
64
- - "--charset=UTF-8"
95
+ rdoc_options: []
65
96
  require_paths:
66
97
  - lib
67
98
  required_ruby_version: !ruby/object:Gem::Requirement
68
99
  requirements:
69
100
  - - ">="
70
101
  - !ruby/object:Gem::Version
71
- version: '0'
102
+ version: '2.3'
72
103
  required_rubygems_version: !ruby/object:Gem::Requirement
73
104
  requirements:
74
105
  - - ">="
75
106
  - !ruby/object:Gem::Version
76
107
  version: '0'
77
108
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.5.1
109
+ rubygems_version: 3.1.2
80
110
  signing_key:
81
- specification_version: 3
82
- summary: Library of Congress Classification classes and subclasses
111
+ specification_version: 4
112
+ summary: Library of Congress Classification classes and subclasses.
83
113
  test_files:
84
114
  - test/helper.rb
85
115
  - test/test_lcclasses.rb
86
- has_rdoc:
data/README.markdown DELETED
@@ -1,66 +0,0 @@
1
- # LCCLasses
2
-
3
- A Ruby gem that provides the Library of Congress Classification system main classes and subclasses along with some convenience menthods.
4
-
5
- To install:
6
-
7
- gem install lcclasses
8
-
9
- ## Usage
10
-
11
- To find a classification code:
12
-
13
- LCClasses.find_main_class_by_code("T")
14
- => ["T", "Technology (General)"]
15
- LCClasses.find_subclass_by_code("AM")
16
- => ["AM", "Museums. Collectors and collecting"]
17
- LCClasses.find_all_by_code("E")
18
- => # returns the main "E" class and all subclasses in nested array
19
- LCClasses.main_classes
20
- => # returns all main classes
21
- LCClasses.subclasses
22
- => # returns all subclasses
23
-
24
- The entire set of classes can be retrieved in 3 formats:
25
-
26
- LCClasses::CLASS_HASH
27
- => # nested hash of classes and subclasses
28
- LCClasses.nested
29
- => # nested array of classes and subclasses as LCClasses::LCClass objects
30
- LCClasses.flat
31
- => # flat array of classes and subclasses as LCClasses::LCClass objects
32
-
33
- The CLASS\_HASH constant is in the following format (truncated example):
34
-
35
- { "A" => {
36
- :name => "General Works",
37
- :subclasses => {
38
- "AC" => { :name => "Collections; Series; Collected works" }
39
- }
40
- }
41
- }
42
-
43
- Classes are returned as specialized LCClasses::Class arrays in the format `[code, name]`. In the case of nested LCClasses:LCClass objects, they are in the format `[main_class_code, main_class_name, [[subclass_code, subclass_name]]]`. These objects are normal arrays with the following methods added:
44
-
45
- @class = LCClasses.find_main_class_by_code("M")
46
- @class.code
47
- => "M"
48
- @class.name
49
- => "Music"
50
- @class.subclasses
51
- => [["M", "Music"], ["ML", "Literature on music"], ["MT", "Instruction and study"]]
52
-
53
- ## Note on Patches/Pull Requests
54
-
55
- * Fork the project.
56
- * Make your feature addition or bug fix.
57
- * Add tests for it. This is important so I don't break it in a
58
- future version unintentionally.
59
- * Commit, do not mess with rakefile, version, or history.
60
- (if you want to have your own version, that is fine but
61
- bump version in a commit by itself I can ignore when I pull)
62
- * Send me a pull request. Bonus points for topic branches.
63
-
64
- ## Copyright
65
-
66
- Copyright (c) 2010 William Melody. See LICENSE for details.