https://github.com/xwmx/lcclasses
Ruby gem for listing and manipulating Library of Congress Classification classes and subclasses
https://github.com/xwmx/lcclasses
classification congress-classification ruby rubygems
Last synced: 5 months ago
JSON representation
Ruby gem for listing and manipulating Library of Congress Classification classes and subclasses
- Host: GitHub
- URL: https://github.com/xwmx/lcclasses
- Owner: xwmx
- License: mit
- Created: 2010-02-26T01:39:01.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2021-11-14T02:50:46.000Z (almost 4 years ago)
- Last Synced: 2025-05-03T18:03:09.625Z (5 months ago)
- Topics: classification, congress-classification, ruby, rubygems
- Language: Ruby
- Homepage:
- Size: 50.8 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LCCLasses
[](https://travis-ci.org/xwmx/lcclasses)
A Ruby gem that provides the
[Library of Congress Classification](https://www.loc.gov/catdir/cpso/lcc.html)
system main classes and subclasses along with some convenience methods.## Installation
LCCLasses is available on [RubyGems](https://rubygems.org/gems/lcclasses):
```bash
gem install lcclasses
```To install with [Bundler](https://bundler.io/), add the following to your
Gemfile:```ruby
gem 'lcclasses'
```Then run `bundle install`
## Usage
To find a classification code:
```ruby
LCClasses.find_main_class_by_code("T")
=> ["T", "Technology (General)"]
LCClasses.find_subclass_by_code("AM")
=> ["AM", "Museums. Collectors and collecting"]
LCClasses.find_all_by_code("E")
=> # returns the main "E" class and all subclasses in nested array
LCClasses.main_classes
=> # returns all main classes
LCClasses.subclasses
=> # returns all subclasses
```The entire set of classes can be retrieved in 3 formats:
```ruby
LCClasses::CLASS_HASH
=> # nested hash of classes and subclasses
LCClasses.nested
=> # nested array of classes and subclasses as LCClasses::LCClass objects
LCClasses.flat
=> # flat array of classes and subclasses as LCClasses::LCClass objects
```The `CLASS_HASH` constant is in the following format (truncated example):
```ruby
{ "A" => {
:name => "General Works",
:subclasses => {
"AC" => { :name => "Collections; Series; Collected works" }
}
}
}
```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:```ruby
@class = LCClasses.find_main_class_by_code("M")
@class.code
=> "M"
@class.name
=> "Music"
@class.subclasses
=> [["M", "Music"], ["ML", "Literature on music"], ["MT", "Instruction and study"]]
```## Note on Patches/Pull Requests
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but
bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.## Copyright
Copyright (c) 2010 William Melody. See LICENSE for details.