Skip to content

Commit 478b2c2

Browse files
committed
initial commit
0 parents  commit 478b2c2

16 files changed

+304
-0
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
10+
Gemfile.lock
11+
12+
# rspec failure tracking
13+
.rspec_status

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
sudo: false
3+
language: ruby
4+
cache: bundler
5+
rvm:
6+
- 2.3.3
7+
before_install: gem install bundler -v 2.0.2

Gemfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'marc_to_argot', github: 'trln/marc-to-argot'
4+
gem 'sierra_postgres_utilities', github: 'UNC-Libraries/sierra-postgres-utilities'
5+
gem 'sierra_postgres_utilities-derivatives', github: 'UNC-Libraries/sierra-postgres-utilities-derivatives'
6+
7+
# Specify your gem's dependencies in sierra_postgres_utilities-argot.gemspec
8+
gemspec

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SierraPostgresUtilities::Argot
2+
3+
[sierra_postgres_utilities gem](https://github.com/UNC-Libraries/sierra-postgres-utilities) addon to allow programmatic access to [Argot](https://github.com/trln/marc-to-argot) for a Sierra
4+
bib record (or TRLN Discovery bib).
5+
6+
## Installation
7+
8+
```bash
9+
bundle install
10+
bundle exec rake install
11+
```
12+
13+
## Usage
14+
15+
```ruby
16+
require 'sierra_postgres_utilities/argot'
17+
18+
bib = Sierra::Data::Bib.first
19+
bib.argot
20+
#=> {"record_data_source"=>["ILSMARC"], "publication_year"=>[1976],
21+
# "date_cataloged"=>["2004-10-01T04:00:00Z"], "language"=>["English"],
22+
# "lang_code"=>["eng"], "publisher"=>[{"value"=>"Black Sparrow Press"}],
23+
# "names"=>[{"name"=>"Kelly, Robert, 1935-", "type"=>"creator"}], ...
24+
25+
trln = bib.trln_discovery_record
26+
trln.argot
27+
#=> same as above
28+
```

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "bundler/gem_tasks"
2+
require "rspec/core/rake_task"
3+
4+
RSpec::Core::RakeTask.new(:spec)
5+
6+
task :default => :spec

bin/console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "sierra_postgres_utilities/argot"
5+
6+
# You can add fixtures and/or initialization code here to make experimenting
7+
# with your gem easier. You can also use a different console, if you like.
8+
9+
# (If you use this, don't forget to add pry to your Gemfile!)
10+
# require "pry"
11+
# Pry.start
12+
13+
require "irb"
14+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'sierra_postgres_utilities'
2+
require 'sierra_postgres_utilities/derivatives'
3+
4+
require 'marc_to_argot'
5+
6+
module Sierra
7+
# Allows programmatic access to Argot for a Sierra / TRLN Discovery bib.
8+
module Argot
9+
# marc_to_argot may appear differently (hyphens vs underscore) in the load
10+
# path depending on whether or not bundler is involved
11+
MTA_DATA_DIR =
12+
File.join($LOAD_PATH.select { |x| x.match 'marc[-_]to[-_]argot' }.first,
13+
'data')
14+
15+
COLLECTION = 'unc'.freeze
16+
17+
autoload :VERSION, 'sierra_postgres_utilities/argot/version'
18+
autoload :Indexer, 'sierra_postgres_utilities/argot/indexer'
19+
20+
require 'sierra_postgres_utilities/argot/td_argot'
21+
end
22+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
module Sierra
2+
module Argot
3+
module TrajectLoader
4+
# This module taken almost exactly from spec files of:
5+
# https://github.com/trln/marc-to-argot
6+
# under the following license:
7+
#
8+
# The MIT License (MIT)
9+
#
10+
# Copyright (c) 2017 Luke Aeschleman
11+
#
12+
# Permission is hereby granted, free of charge, to any person obtaining a copy
13+
# of this software and associated documentation files (the "Software"), to deal
14+
# in the Software without restriction, including without limitation the rights
15+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
# copies of the Software, and to permit persons to whom the Software is
17+
# furnished to do so, subject to the following conditions:
18+
#
19+
# The above copyright notice and this permission notice shall be included in
20+
# all copies or substantial portions of the Software.
21+
#
22+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28+
# THE SOFTWARE.
29+
30+
def create_settings(collection, data_dir, extension)
31+
spec = MarcToArgot::SpecGenerator.new(collection)
32+
marc_source_type = extension == 'mrc' ? 'binary' : 'xml'
33+
flatten_attributes = YAML.load_file("#{data_dir}/flatten_attributes.yml")
34+
override = File.exist?("#{data_dir}/#{collection}/overrides.yml") ? YAML.load_file("#{data_dir}/#{collection}/overrides.yml") : []
35+
36+
{
37+
'argot_writer.flatten_attributes' => flatten_attributes,
38+
'argot_writer.pretty_print' => false,
39+
'writer_class_name' => 'Traject::ArgotWriter',
40+
'specs' => spec.generate_spec,
41+
'processing_thread_pool' => 1,
42+
'marc_source.type' => marc_source_type,
43+
'marc_source.encoding' => 'utf-8',
44+
'override' => override,
45+
'log_level' => :error
46+
}
47+
end
48+
49+
def load_indexer(collection = 'argot', extension = 'xml')
50+
data_dir = MTA_DATA_DIR
51+
conf_files = ["#{data_dir}/extensions.rb", "#{data_dir}/argot/traject_config.rb", "#{data_dir}/#{collection}/traject_config.rb"]
52+
indexer_class = MarcToArgot::Indexers.find(collection.to_sym)
53+
traject_indexer = indexer_class.new create_settings(collection, data_dir, extension)
54+
conf_files.each do |conf_path|
55+
begin
56+
traject_indexer.load_config_file(conf_path)
57+
rescue Errno::ENOENT, Errno::EACCES => e
58+
raise "Could not read configuration file '#{conf_path}', exiting..."
59+
rescue Traject::Indexer::ConfigLoadError => e
60+
raise e
61+
rescue StandardError => e
62+
raise e
63+
end
64+
end
65+
traject_indexer
66+
end
67+
end
68+
69+
# A Traject Indexer to transform MARC into Argot
70+
class Indexer
71+
include TrajectLoader
72+
73+
def indexer
74+
@indexer ||= load_indexer(COLLECTION, 'mrc')
75+
end
76+
end
77+
end
78+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Sierra
2+
module Argot
3+
module TDArgot
4+
def argot
5+
@argot ||= TDArgot.argot(self)
6+
end
7+
8+
# Transforms TRLN Discovery record's MARC into Argot
9+
def self.argot(trln_rec)
10+
indexer.map_record(trln_rec.altmarc)
11+
end
12+
13+
def self.indexer
14+
@indexer ||= Indexer.new.indexer
15+
end
16+
end
17+
end
18+
19+
module Derivatives
20+
class TRLNDiscoveryRecord
21+
include Sierra::Argot::TDArgot
22+
end
23+
end
24+
25+
module Data
26+
class Bib
27+
def argot
28+
@argot ||= trln_discovery_record.argot
29+
end
30+
end
31+
end
32+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Sierra
2+
module Argot
3+
VERSION = '1.0.0'.freeze
4+
end
5+
end
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
lib = File.expand_path('lib', __dir__)
2+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3+
require 'sierra_postgres_utilities/argot/version'
4+
5+
Gem::Specification.new do |spec|
6+
spec.name = 'sierra_postgres_utilities-argot'
7+
spec.version = Sierra::Argot::VERSION
8+
spec.authors = ['ldss-jm']
9+
spec.email = ['[email protected]']
10+
11+
spec.summary = 'Access Argot for a Sierra (or TRLN Discovery) bib'
12+
spec.homepage = 'https://github.com/UNC-Libraries/sierra-postgres-utilities-argot'
13+
14+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
15+
16+
spec.metadata['homepage_uri'] = spec.homepage
17+
spec.metadata['source_code_uri'] = spec.homepage
18+
spec.metadata['changelog_uri'] = "#{spec.homepage}/releases"
19+
20+
# Specify which files should be added to the gem when it is released.
21+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24+
end
25+
26+
spec.bindir = 'exe'
27+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28+
spec.require_paths = ['lib']
29+
30+
spec.add_development_dependency 'bundler', '~> 2.0'
31+
spec.add_development_dependency 'rake', '~> 10.0'
32+
spec.add_development_dependency 'rspec', '~> 3.0'
33+
34+
spec.add_runtime_dependency 'marc_to_argot', '~> 0.4.0'
35+
spec.add_runtime_dependency 'sierra_postgres_utilities', '~> 0.3.0'
36+
spec.add_runtime_dependency 'sierra_postgres_utilities-derivatives', '~> 1.0.0'
37+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe Sierra::Argot do
4+
it 'has a version number' do
5+
expect(Sierra::Argot::VERSION).not_to be nil
6+
end
7+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe Sierra do
4+
let(:bib) { Sierra::Data::Bib.first }
5+
let(:trln) { bib.trln_discovery_record }
6+
7+
describe Sierra::Derivatives::TRLNDiscoveryRecord do
8+
describe '#argot' do
9+
it 'returns hash of Argot json' do
10+
expect(trln.argot['record_data_source']).to include 'ILSMARC'
11+
end
12+
end
13+
end
14+
15+
describe Sierra::Data::Bib do
16+
describe '#argot' do
17+
it "returns hash of Argot json (for bib's TRLNDiscoveryRecord)" do
18+
expect(bib.argot).to equal trln.argot
19+
end
20+
end
21+
end
22+
end

spec/spec_helper.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'bundler/setup'
2+
require 'sierra_postgres_utilities/argot'
3+
4+
RSpec.configure do |config|
5+
# Enable flags like --only-failures and --next-failure
6+
config.example_status_persistence_file_path = '.rspec_status'
7+
8+
# Disable RSpec exposing methods globally on `Module` and `main`
9+
config.disable_monkey_patching!
10+
11+
config.expect_with :rspec do |c|
12+
c.syntax = :expect
13+
end
14+
end

0 commit comments

Comments
 (0)