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 +5 -5
- data/.document +1 -1
- data/README.md +76 -0
- data/Rakefile +3 -3
- data/lcclasses.gemspec +24 -42
- data/lib/lcclasses.rb +17 -12
- data/test/helper.rb +4 -2
- data/test/test_lcclasses.rb +4 -4
- metadata +43 -14
- data/README.markdown +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 49b2f5106b678c366efacf049369567d895f1e9869db97cdd476b06b02791adb
|
4
|
+
data.tar.gz: 8e5ac470b862993e636db8a97980b83e4773f6fdc3ce4af3bf0b8285291ef840
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa3770b6bb17e9002932fccd05eb5154fa4a2b8b79c60c47adf42a5484280021753a41da01a07612fed8257670f60863fc336a9afee384bc5cfd9b318f04e9ec
|
7
|
+
data.tar.gz: bdcda9e0a43f8e36257d16b2b5434eb5a6416eaeda132d7172f32c9a1f238ba9b171ac10df807b5ba3b9bcac062eb9bf01f9e953a6e9800154994315a3eccc6e
|
data/.document
CHANGED
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
|
-
#
|
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
|
-
|
9
|
-
|
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
|
-
#
|
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 =
|
8
|
-
s.version = '0.
|
9
|
-
|
10
|
-
s.
|
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.
|
13
|
-
s.
|
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
|
-
|
14
|
+
'README.md'
|
18
15
|
]
|
19
16
|
s.files = [
|
20
17
|
'.document',
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
29
|
+
'test/test_lcclasses.rb'
|
39
30
|
]
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
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
|
-
|
27
|
-
|
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
|
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
|
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
|
-
|
7
|
-
|
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'
|
data/test/test_lcclasses.rb
CHANGED
@@ -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([]) { |
|
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'
|
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.
|
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:
|
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
|
-
|
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.
|
79
|
+
- README.md
|
48
80
|
files:
|
49
81
|
- ".document"
|
50
82
|
- ".gitignore"
|
51
83
|
- LICENSE
|
52
|
-
- README.
|
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/
|
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: '
|
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
|
-
|
79
|
-
rubygems_version: 2.5.1
|
109
|
+
rubygems_version: 3.1.2
|
80
110
|
signing_key:
|
81
|
-
specification_version:
|
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.
|