lcclasses 0.0.0
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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.markdown +66 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lcclasses.gemspec +54 -0
- data/lib/lcclasses.rb +404 -0
- data/test/test_helper.rb +10 -0
- data/test/test_lcclasses.rb +72 -0
- metadata +75 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 William Melody
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,66 @@
|
|
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
|
+
LCClases.nested
|
29
|
+
=> # nested array of classes and subclasses as LCClasses::LCClass objects
|
30
|
+
LCClases.flat
|
31
|
+
=> # flat array of classes and subclasses as LCClasses::LCClass objects
|
32
|
+
|
33
|
+
The CLASS\_HASH conststant 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.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "lcclasses"
|
8
|
+
gem.summary = %Q{Library of Congress Classification classes and subclasses}
|
9
|
+
gem.description = %Q{Library of Congress Classification classes and subclasses}
|
10
|
+
gem.email = "hi@williammelody.com"
|
11
|
+
gem.homepage = "http://github.com/autodata/lcclasses"
|
12
|
+
gem.authors = ["William Melody"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION')
|
47
|
+
version = File.read('VERSION')
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "lcclasses #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lcclasses.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
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 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{lcclasses}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["William Melody"]
|
12
|
+
s.date = %q{2010-02-25}
|
13
|
+
s.description = %q{Library of Congress Classification classes and subclasses}
|
14
|
+
s.email = %q{hi@williammelody.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lcclasses.gemspec",
|
27
|
+
"lib/lcclasses.rb",
|
28
|
+
"test/test_helper.rb",
|
29
|
+
"test/test_lcclasses.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/autodata/lcclasses}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{Library of Congress Classification classes and subclasses}
|
36
|
+
s.test_files = [
|
37
|
+
"test/test_helper.rb",
|
38
|
+
"test/test_lcclasses.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/lib/lcclasses.rb
ADDED
@@ -0,0 +1,404 @@
|
|
1
|
+
module LCClasses
|
2
|
+
class LCClass < Array
|
3
|
+
|
4
|
+
# Convert nested LCClasses::CLASS_HASH to nested array.
|
5
|
+
def self.nest(hash)
|
6
|
+
return self[] if hash.nil?
|
7
|
+
hash.sort { |a,b| a[0] <=> b[0] }.inject(self[]) do |result, klass|
|
8
|
+
if klass[1][:subclasses]
|
9
|
+
result << self[klass[0],klass[1][:name], self.nest(klass[1][:subclasses])]
|
10
|
+
else
|
11
|
+
result << self[klass[0],klass[1][:name]]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Convert nested LCClasses::CLASS_HASH to flat array.
|
17
|
+
def self.flatten(hash)
|
18
|
+
return self[] if hash.nil?
|
19
|
+
hash.sort { |a,b| a[0] <=> b[0] }.inject(self[]) do |result, klass|
|
20
|
+
result << self[klass[0],klass[1][:name]]
|
21
|
+
result += self.flatten(klass[1][:subclasses])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return the subclasses of this class, if any.
|
26
|
+
def subclasses
|
27
|
+
return unless i = LCClasses::CLASS_HASH[self[0]]
|
28
|
+
LCClasses::LCClass.nest(i[:subclasses])
|
29
|
+
end
|
30
|
+
|
31
|
+
# The class code.
|
32
|
+
def code; self[0] end
|
33
|
+
# THe class name.
|
34
|
+
def name; self[1] end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Library of Congress Main Classes and Subclasses
|
38
|
+
CLASS_HASH = {
|
39
|
+
"A" => {
|
40
|
+
:name => "General Works",
|
41
|
+
:subclasses => {
|
42
|
+
"AC" => { :name => "Collections; Series; Collected works" },
|
43
|
+
"AE" => { :name => "Encyclopedias" },
|
44
|
+
"AG" => { :name => "Dictionaries and other general reference works" },
|
45
|
+
"AI" => { :name => "Indexes" },
|
46
|
+
"AM" => { :name => "Museums. Collectors and collecting" },
|
47
|
+
"AN" => { :name => "AN Newspapers" },
|
48
|
+
"AP" => { :name => "Periodicals" },
|
49
|
+
"AS" => { :name => "Academies and learned societies" },
|
50
|
+
"AY" => { :name => "Yearbooks. Almanacs. Directories" },
|
51
|
+
"AZ" => { :name => "History of scholarship and learning. The humanities" },
|
52
|
+
}
|
53
|
+
},
|
54
|
+
"B" => {
|
55
|
+
:name => "Philosophy, Psychology, Religion",
|
56
|
+
:subclasses => {
|
57
|
+
"B" => { :name => "Philosophy (General)" },
|
58
|
+
"BC" => { :name => "Logic" },
|
59
|
+
"BD" => { :name => "Speculative philosophy" },
|
60
|
+
"BF" => { :name => "Psychology" },
|
61
|
+
"BH" => { :name => "Aesthetics" },
|
62
|
+
"BJ" => { :name => "Ethics" },
|
63
|
+
"BL" => { :name => "Religions; Mythology; Rationalism" },
|
64
|
+
"BM" => { :name => "Judaism" },
|
65
|
+
"BP" => { :name => "Islam; Bahaism; Theosophy, etc." },
|
66
|
+
"BQ" => { :name => "Buddhism" },
|
67
|
+
"BR" => { :name => "Christianity" },
|
68
|
+
"BS" => { :name => "The Bible" },
|
69
|
+
"BT" => { :name => "Doctrinal Theology" },
|
70
|
+
"BV" => { :name => "Practical Theology" },
|
71
|
+
"BX" => { :name => "Christian Denominations" },
|
72
|
+
}
|
73
|
+
},
|
74
|
+
"C" => {
|
75
|
+
:name => "Auxiliary Sciences of History (General)",
|
76
|
+
:subclasses => {
|
77
|
+
"CB" => { :name => "History of Civilization" },
|
78
|
+
"CC" => { :name => "Archaeology" },
|
79
|
+
"CD" => { :name => "Diplomatics. Archives. Seals" },
|
80
|
+
"CE" => { :name => "Technical Chronology. Calendar" },
|
81
|
+
"CJ" => { :name => "Numismatics" },
|
82
|
+
"CN" => { :name => "Inscriptions. Epigraphy" },
|
83
|
+
"CR" => { :name => "Heraldry" },
|
84
|
+
"CS" => { :name => "Genealogy" },
|
85
|
+
"CT" => { :name => "Biography" },
|
86
|
+
}
|
87
|
+
},
|
88
|
+
"D" => {
|
89
|
+
:name => "World History and History of Europe, Asia, Africa, Australia, New Zealand, etc.",
|
90
|
+
:subclasses => {
|
91
|
+
"D" => { :name => "History (General)" },
|
92
|
+
"DA" => { :name => "Great Britain" },
|
93
|
+
"DAW" => { :name => "Central Europe" },
|
94
|
+
"DB" => { :name => "Austria - Liechtenstein - Hungary - Czechoslovakia" },
|
95
|
+
"DC" => { :name => "France - Andorra - Monaco" },
|
96
|
+
"DD" => { :name => "Germany" },
|
97
|
+
"DE" => { :name => "Greco-Roman World" },
|
98
|
+
"DF" => { :name => "Greece" },
|
99
|
+
"DG" => { :name => "Italy - Malta" },
|
100
|
+
"DH" => { :name => "Low Countries - Benelux Countries (Continued on next page)" },
|
101
|
+
"DJ" => { :name => "Netherlands (Holland)" },
|
102
|
+
"DJK" => { :name => "Eastern Europe (General)" },
|
103
|
+
"DK" => { :name => "Russia. Soviet Union. Former Soviet Republics - Poland" },
|
104
|
+
"DL" => { :name => "Northern Europe. Scandinavia" },
|
105
|
+
"DP" => { :name => "Spain - Portugal" },
|
106
|
+
"DQ" => { :name => "Switzerland" },
|
107
|
+
"DR" => { :name => "Balkan Peninsula" },
|
108
|
+
"DS" => { :name => "Asia" },
|
109
|
+
"DT" => { :name => "Africa" },
|
110
|
+
"DU" => { :name => "Oceania (South Seas)" },
|
111
|
+
"DX" => { :name => "Gypsies" },
|
112
|
+
}
|
113
|
+
},
|
114
|
+
"E" => {
|
115
|
+
:name => "History of America, United States",
|
116
|
+
},
|
117
|
+
"F" => {
|
118
|
+
:name => "Local History of the United States and British, Dutch, French, and Latin America",
|
119
|
+
},
|
120
|
+
"G" => {
|
121
|
+
:name => "Geography, Anthropology, Recreation",
|
122
|
+
:subclasses => {
|
123
|
+
"G" => { :name => "Geography (General). Atlases. Maps" },
|
124
|
+
"GA" => { :name => "Mathematical geography. Cartography" },
|
125
|
+
"GB" => { :name => "Physical geography" },
|
126
|
+
"GC" => { :name => "Oceanography" },
|
127
|
+
"GE" => { :name => "Environmental Sciences" },
|
128
|
+
"GF" => { :name => "Human ecology. Anthropogeography" },
|
129
|
+
"GN" => { :name => "Anthropology" },
|
130
|
+
"GR" => { :name => "Folklore" },
|
131
|
+
"GT" => { :name => "Manners and customs (General)" },
|
132
|
+
"GV" => { :name => "Recreation. Leisure" },
|
133
|
+
}
|
134
|
+
},
|
135
|
+
"H" => {
|
136
|
+
:name => "Social Sciences",
|
137
|
+
:subclasses => {
|
138
|
+
"H" => { :name => "Social sciences (General)" },
|
139
|
+
"HA" => { :name => "Statistics" },
|
140
|
+
"HB" => { :name => "Economic theory. Demography" },
|
141
|
+
"HC" => { :name => "Economic history and conditions" },
|
142
|
+
"HD" => { :name => "Industries. Land use. Labor" },
|
143
|
+
"HE" => { :name => "Transportation and communications" },
|
144
|
+
"HF" => { :name => "Commerce" },
|
145
|
+
"HG" => { :name => "Finance" },
|
146
|
+
"HJ" => { :name => "Public finance" },
|
147
|
+
"HM" => { :name => "Sociology (General)" },
|
148
|
+
"HN" => { :name => "Social history and conditions. Social problems. Social reform" },
|
149
|
+
"HQ" => { :name => "The family. Marriage. Women" },
|
150
|
+
"HS" => { :name => "Societies: secret, benevolent, etc." },
|
151
|
+
"HT" => { :name => "Communities. Classes. Races" },
|
152
|
+
"HV" => { :name => "Social pathology. Social and public welfare. Criminology" },
|
153
|
+
"HX" => { :name => "Socialism. Communism. Anarchism" },
|
154
|
+
}
|
155
|
+
},
|
156
|
+
"J" => {
|
157
|
+
:name => "Political Sciences",
|
158
|
+
:subclasses => {
|
159
|
+
"J" => { :name => "General legislative and executive papers" },
|
160
|
+
"JA" => { :name => "Political science (General)" },
|
161
|
+
"JC" => { :name => "Political theory" },
|
162
|
+
"JF" => { :name => "Political institutions and public administration" },
|
163
|
+
"JJ" => { :name => "Political institutions and public administration (North America)" },
|
164
|
+
"JK" => { :name => "Political institutions and public administration (United States)" },
|
165
|
+
"JL" => { :name => "Political institutions and public administration (Canada, Latin America, etc.)" },
|
166
|
+
"JN" => { :name => "Political institutions and public administration (Europe)" },
|
167
|
+
"JQ" => { :name => "Political institutions and public administration (Asia, Africa, Australia, Pacific Area, etc.)" },
|
168
|
+
"JS" => { :name => "Local government. Municipal government" },
|
169
|
+
"JV" => { :name => "Colonies and colonization. Emigration and immigration. International migration" },
|
170
|
+
"JX" => { :name => "International law, see JZ and KZ (obsolete)" },
|
171
|
+
"JZ" => { :name => "International relations" },
|
172
|
+
}
|
173
|
+
},
|
174
|
+
"K" => {
|
175
|
+
:name => "Law",
|
176
|
+
:subclasses => {
|
177
|
+
"K" => { :name => "Law in general. Comparative and uniform law. Jurisprudence" },
|
178
|
+
"KB" => { :name => "Religious law in general. Comparative religious law. Jurisprudence" },
|
179
|
+
"KBM" => { :name => "Jewish law" },
|
180
|
+
"KBP" => { :name => "Islamic law" },
|
181
|
+
"KBR" => { :name => "History of canon law" },
|
182
|
+
"KBU" => { :name => "Law of the Roman Catholic Church. The Holy See" },
|
183
|
+
"KD-KDK" => { :name => "United Kingdom and Ireland" },
|
184
|
+
"KDZ" => { :name => "America. North America" },
|
185
|
+
"KE" => { :name => "Canada" },
|
186
|
+
"KF" => { :name => "United States" },
|
187
|
+
"KG" => { :name => "Latin America - Mexico and Central America - West Indies. Caribbean area" },
|
188
|
+
"KH" => { :name => "South America" },
|
189
|
+
"KJ-KKZ" => { :name => "Europe" },
|
190
|
+
"KL-KWX" => { :name => "Asia and Eurasia, Africa, Pacific Area, and Antarctica" },
|
191
|
+
"KZ" => { :name => "Law of nations" },
|
192
|
+
}
|
193
|
+
},
|
194
|
+
"L" => {
|
195
|
+
:name => "Education",
|
196
|
+
:subclasses => {
|
197
|
+
"L" => { :name => "Education (General)" },
|
198
|
+
"LA" => { :name => "History of education" },
|
199
|
+
"LB" => { :name => "Theory and practice of education" },
|
200
|
+
"LC" => { :name => "Special aspects of education" },
|
201
|
+
"LD" => { :name => "Individual institutions - United States" },
|
202
|
+
"LE" => { :name => "Individual institutions - America (except United States)" },
|
203
|
+
"LF" => { :name => "Individual institutions - Europe" },
|
204
|
+
"LG" => { :name => "Individual institutions - Asia, Africa, Indian Ocean islands, Australia, New Zealand, Pacific islands" },
|
205
|
+
"LH" => { :name => "College and school magazines and papers" },
|
206
|
+
"LJ" => { :name => "Student fraternities and societies, United States" },
|
207
|
+
"LT" => { :name => "Textbooks" },
|
208
|
+
}
|
209
|
+
},
|
210
|
+
"M" => {
|
211
|
+
:name => "Music",
|
212
|
+
:subclasses => {
|
213
|
+
"M" => { :name => "Music" },
|
214
|
+
"ML" => { :name => "Literature on music" },
|
215
|
+
"MT" => { :name => "Instruction and study" },
|
216
|
+
}
|
217
|
+
},
|
218
|
+
"N" => {
|
219
|
+
:name => "Fine Arts",
|
220
|
+
:subclasses => {
|
221
|
+
"N" => { :name => "Visual arts" },
|
222
|
+
"NA" => { :name => "Architecture" },
|
223
|
+
"NB" => { :name => "Sculpture" },
|
224
|
+
"NC" => { :name => "Drawing. Design. Illustration" },
|
225
|
+
"ND" => { :name => "Painting" },
|
226
|
+
"NE" => { :name => "Print media" },
|
227
|
+
"NK" => { :name => "Decorative arts" },
|
228
|
+
"NX" => { :name => "Arts in general" },
|
229
|
+
}
|
230
|
+
},
|
231
|
+
"P" => {
|
232
|
+
:name => "Language and Literature",
|
233
|
+
:subclasses => {
|
234
|
+
"P" => { :name => "Philology. Linguistics" },
|
235
|
+
"PA" => { :name => "Greek language and literature. Latin language and literature" },
|
236
|
+
"PB" => { :name => "Modern languages. Celtic languages" },
|
237
|
+
"PC" => { :name => "Romanic languages" },
|
238
|
+
"PD" => { :name => "Germanic languages. Scandinavian languages" },
|
239
|
+
"PE" => { :name => "English language" },
|
240
|
+
"PF" => { :name => "West Germanic languages" },
|
241
|
+
"PG" => { :name => "Slavic languages and literatures. Baltic languages. Albanian language" },
|
242
|
+
"PH" => { :name => "Uralic languages. Basque language" },
|
243
|
+
"PJ" => { :name => "Oriental languages and literatures" },
|
244
|
+
"PK" => { :name => "Indo-Iranian languages and literatures" },
|
245
|
+
"PL" => { :name => "Languages and literatures of Eastern Asia, Africa, Oceania" },
|
246
|
+
"PM" => { :name => "Hyperborean, Indian, and artificial languages" },
|
247
|
+
"PN" => { :name => "Literature (General)" },
|
248
|
+
"PQ" => { :name => "French literature - Italian literature - Spanish literature - Portuguese literature" },
|
249
|
+
"PR" => { :name => "English literature" },
|
250
|
+
"PS" => { :name => "American literature" },
|
251
|
+
"PT" => { :name => "German literature - Dutch literature - Flemish literature since 1830 -Afrikaans literature - Scandinavian literature - Old Norse literature: Old Icelandic and Old Norwegian - Modern Icelandic literature - Faroese literature - Danish literature - Norwegian literature - Swedish literature" },
|
252
|
+
"PZ" => { :name => "Fiction and juvenile belles lettres" },
|
253
|
+
}
|
254
|
+
},
|
255
|
+
"Q" => {
|
256
|
+
:name => "Science",
|
257
|
+
:subclasses => {
|
258
|
+
"Q" => { :name => "Science (General)" },
|
259
|
+
"QA" => { :name => "Mathematics" },
|
260
|
+
"QB" => { :name => "Astronomy" },
|
261
|
+
"QC" => { :name => "Physics" },
|
262
|
+
"QD" => { :name => "Chemistry" },
|
263
|
+
"QE" => { :name => "Geology" },
|
264
|
+
"QH" => { :name => "Natural history - Biology" },
|
265
|
+
"QK" => { :name => "Botany" },
|
266
|
+
"QL" => { :name => "Zoology" },
|
267
|
+
"QM" => { :name => "Human anatomy" },
|
268
|
+
"QP" => { :name => "Physiology" },
|
269
|
+
"QR" => { :name => "Microbiology" },
|
270
|
+
}
|
271
|
+
},
|
272
|
+
"R" => {
|
273
|
+
:name => "Medicine",
|
274
|
+
:subclasses => {
|
275
|
+
"R" => { :name => "Medicine (General)" },
|
276
|
+
"RA" => { :name => "Public aspects of medicine" },
|
277
|
+
"RB" => { :name => "Pathology" },
|
278
|
+
"RC" => { :name => "Internal medicine" },
|
279
|
+
"RD" => { :name => "Surgery" },
|
280
|
+
"RE" => { :name => "Ophthalmology" },
|
281
|
+
"RF" => { :name => "Otorhinolaryngology" },
|
282
|
+
"RG" => { :name => "Gynecology and obstetrics" },
|
283
|
+
"RJ" => { :name => "Pediatrics" },
|
284
|
+
"RK" => { :name => "Dentistry" },
|
285
|
+
"RL" => { :name => "Dermatology" },
|
286
|
+
"RM" => { :name => "Therapeutics. Pharmacology" },
|
287
|
+
"RS" => { :name => "Pharmacy and materia medica" },
|
288
|
+
"RT" => { :name => "Nursing" },
|
289
|
+
"RV" => { :name => "Botanic, Thomsonian, and eclectic medicine" },
|
290
|
+
"RX" => { :name => "Homeopathy" },
|
291
|
+
"RZ" => { :name => "Other systems of medicine" },
|
292
|
+
}
|
293
|
+
},
|
294
|
+
"S" => {
|
295
|
+
:name => "Agriculture",
|
296
|
+
:subclasses => {
|
297
|
+
"S" => { :name => "Agriculture (General)" },
|
298
|
+
"SB" => { :name => "Plant culture" },
|
299
|
+
"SD" => { :name => "Forestry" },
|
300
|
+
"SF" => { :name => "Animal culture" },
|
301
|
+
"SH" => { :name => "Aquaculture. Fisheries. Angling" },
|
302
|
+
"SK" => { :name => "Hunting sports" },
|
303
|
+
}
|
304
|
+
},
|
305
|
+
"T" => {
|
306
|
+
:name => "Technology",
|
307
|
+
:subclasses => {
|
308
|
+
"T" => { :name => "Technology (General)" },
|
309
|
+
"TA" => { :name => "Engineering (General). Civil engineering" },
|
310
|
+
"TC" => { :name => "Hydraulic engineering. Ocean engineering" },
|
311
|
+
"TD" => { :name => "Environmental technology. Sanitary engineering" },
|
312
|
+
"TE" => { :name => "Highway engineering. Roads and pavements" },
|
313
|
+
"TF" => { :name => "Railroad engineering and operation" },
|
314
|
+
"TG" => { :name => "Bridge engineering" },
|
315
|
+
"TH" => { :name => "Building construction" },
|
316
|
+
"TJ" => { :name => "Mechanical engineering and machinery" },
|
317
|
+
"TK" => { :name => "Electrical engineering. Electronics. Nuclear engineering" },
|
318
|
+
"TL" => { :name => "Motor vehicles. Aeronautics. Astronautics" },
|
319
|
+
"TN" => { :name => "Mining engineering. Metallurgy" },
|
320
|
+
"TP" => { :name => "Chemical technology" },
|
321
|
+
"TR" => { :name => "Photography" },
|
322
|
+
"TS" => { :name => "Manufactures" },
|
323
|
+
"TT" => { :name => "Handicrafts. Arts and crafts" },
|
324
|
+
"TX" => { :name => "Home economics" },
|
325
|
+
}
|
326
|
+
},
|
327
|
+
"U" => {
|
328
|
+
:name => "Military Science",
|
329
|
+
:subclasses => {
|
330
|
+
"U" => { :name => "Military science (General)" },
|
331
|
+
"UA" => { :name => "Armies: Organization, distribution, military situation" },
|
332
|
+
"UB" => { :name => "Military administration" },
|
333
|
+
"UC" => { :name => "Maintenance and transportation" },
|
334
|
+
"UD" => { :name => "Infantry" },
|
335
|
+
"UE" => { :name => "Cavalry. Armor" },
|
336
|
+
"UF" => { :name => "Artillery" },
|
337
|
+
"UG" => { :name => "Military engineering. Air forces" },
|
338
|
+
"UH" => { :name => "Other services" },
|
339
|
+
}
|
340
|
+
},
|
341
|
+
"V" => {
|
342
|
+
:name => "Naval Science",
|
343
|
+
:subclasses => {
|
344
|
+
"V" => { :name => "Naval science (General)" },
|
345
|
+
"VA" => { :name => "Navies: Organization, distribution, naval situation" },
|
346
|
+
"VB" => { :name => "Naval administration" },
|
347
|
+
"VC" => { :name => "Naval maintenance" },
|
348
|
+
"VD" => { :name => "Naval seamen" },
|
349
|
+
"VE" => { :name => "Marines" },
|
350
|
+
"VF" => { :name => "Naval ordnance" },
|
351
|
+
"VG" => { :name => "Minor services of navies" },
|
352
|
+
"VK" => { :name => "Navigation. Merchant marine" },
|
353
|
+
"VM" => { :name => "Naval architecture. Shipbuilding. Marine engineering" },
|
354
|
+
}
|
355
|
+
},
|
356
|
+
"Z" => {
|
357
|
+
:name => "Bibliography, Library Science",
|
358
|
+
:subclasses => {
|
359
|
+
"Z" => { :name => "Books (General). Writing. Paleography. Book industries and trade. Libraries. Bibliography" },
|
360
|
+
"ZA" => { :name => "Information resources (General)" },
|
361
|
+
}
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
# An array of main LC Classes.
|
366
|
+
def self.main_classes
|
367
|
+
CLASS_HASH.map do |k,v|
|
368
|
+
LCClasses::LCClass[k,v[:name]]
|
369
|
+
end.sort
|
370
|
+
end
|
371
|
+
|
372
|
+
# An array of all LC Subclasses.
|
373
|
+
def self.subclasses
|
374
|
+
self.main_classes.inject([]) do |result, main_class|
|
375
|
+
result += main_class.subclasses
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
# A nested array of main classes and subclasses.
|
380
|
+
def self.nested
|
381
|
+
LCClasses::LCClass.nest(LCClasses::CLASS_HASH)
|
382
|
+
end
|
383
|
+
|
384
|
+
# All main classes and subclasses in a flat array.
|
385
|
+
def self.flat
|
386
|
+
LCClasses::LCClass.flatten(LCClasses::CLASS_HASH)
|
387
|
+
end
|
388
|
+
|
389
|
+
# Find an main classe by code.
|
390
|
+
def self.find_main_class_by_code(code)
|
391
|
+
LCClasses.main_classes.detect { |i| i[0] == code.to_s }
|
392
|
+
end
|
393
|
+
|
394
|
+
# Find a subclass by code.
|
395
|
+
def self.find_subclass_by_code(code)
|
396
|
+
LCClasses.subclasses.detect { |i| i[0] == code.to_s }
|
397
|
+
end
|
398
|
+
|
399
|
+
# Find all main classes and subclass that match or start with a code or character.
|
400
|
+
def self.find_all_by_code(code)
|
401
|
+
LCClasses.flat.select { |i| i[0] if (i[0] =~ /^#{code}[A-Z]?[A-Z]?/) }
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestLCClasses < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should "return main classes" do
|
6
|
+
assert_equal 21, LCClasses.main_classes.length
|
7
|
+
end
|
8
|
+
|
9
|
+
should "return subclasses" do
|
10
|
+
assert_equal 223, LCClasses.subclasses.length
|
11
|
+
end
|
12
|
+
|
13
|
+
should "should return flat" do
|
14
|
+
assert_equal 244, LCClasses.flat.length
|
15
|
+
end
|
16
|
+
|
17
|
+
should "should return nested" do
|
18
|
+
assert_equal 21, LCClasses.nested.length
|
19
|
+
assert_equal 223, LCClasses.nested.inject([]) { |r, m| r += m.subclasses }.length
|
20
|
+
end
|
21
|
+
|
22
|
+
should "find main class by code" do
|
23
|
+
assert_equal ["T", "Technology (General)"], LCClasses.find_subclass_by_code("T")
|
24
|
+
end
|
25
|
+
|
26
|
+
should "find subclass by code" do
|
27
|
+
assert_equal ["AM", "Museums. Collectors and collecting"], LCClasses.find_subclass_by_code("AM")
|
28
|
+
end
|
29
|
+
|
30
|
+
should "find all by code" do
|
31
|
+
assert_equal [["E", "History of America, United States"]], LCClasses.find_all_by_code("E")
|
32
|
+
assert_equal 11, LCClasses.find_all_by_code("A").length
|
33
|
+
end
|
34
|
+
|
35
|
+
context "LCCLass" do
|
36
|
+
|
37
|
+
setup {
|
38
|
+
@hash = {
|
39
|
+
"A" => {
|
40
|
+
:name => "General Works",
|
41
|
+
:subclasses => {
|
42
|
+
"AC" => { :name => "Collections; Series; Collected works" }
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
should "flatten code hash" do
|
49
|
+
assert_equal(
|
50
|
+
[["A", "General Works"], ["AC", "Collections; Series; Collected works"]],
|
51
|
+
LCClasses::LCClass.flatten(@hash)
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
should "nest code hash" do
|
56
|
+
assert_equal(
|
57
|
+
[["A", "General Works", [["AC", "Collections; Series; Collected works"]]]],
|
58
|
+
LCClasses::LCClass.nest(@hash)
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
should "return subclasses" do
|
63
|
+
assert_equal 3, LCClasses.find_main_class_by_code("M").subclasses.length
|
64
|
+
assert_equal 0, LCClasses.find_main_class_by_code("E").subclasses.length
|
65
|
+
end
|
66
|
+
|
67
|
+
should "respond to code and name" do
|
68
|
+
assert_equal "A", LCClasses::LCClass["A", "General Works"].code
|
69
|
+
assert_equal "General Works", LCClasses::LCClass["A", "General Works"].name
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lcclasses
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Melody
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-25 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Library of Congress Classification classes and subclasses
|
26
|
+
email: hi@williammelody.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.markdown
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.markdown
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- lcclasses.gemspec
|
42
|
+
- lib/lcclasses.rb
|
43
|
+
- test/test_helper.rb
|
44
|
+
- test/test_lcclasses.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/autodata/lcclasses
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Library of Congress Classification classes and subclasses
|
73
|
+
test_files:
|
74
|
+
- test/test_helper.rb
|
75
|
+
- test/test_lcclasses.rb
|