berkeley_library-av-core 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.dockerignore +391 -0
- data/.github/workflows/build.yml +30 -0
- data/.gitignore +388 -0
- data/.idea/av_core.iml +146 -0
- data/.idea/codeStyles/Project.xml +12 -0
- data/.idea/codeStyles/codeStyleConfig.xml +5 -0
- data/.idea/go.imports.xml +6 -0
- data/.idea/inspectionProfiles/Project_Default.xml +37 -0
- data/.idea/misc.xml +6 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rubocop.yml +241 -0
- data/.ruby-version +1 -0
- data/.simplecov +8 -0
- data/CHANGES.md +38 -0
- data/Gemfile +3 -0
- data/Jenkinsfile +16 -0
- data/LICENSE.md +21 -0
- data/README.md +20 -0
- data/Rakefile +20 -0
- data/av_core.gemspec +49 -0
- data/lib/berkeley_library/av/config.rb +238 -0
- data/lib/berkeley_library/av/constants.rb +30 -0
- data/lib/berkeley_library/av/core/module_info.rb +18 -0
- data/lib/berkeley_library/av/core.rb +7 -0
- data/lib/berkeley_library/av/marc/util.rb +114 -0
- data/lib/berkeley_library/av/marc.rb +52 -0
- data/lib/berkeley_library/av/metadata/README.md +5 -0
- data/lib/berkeley_library/av/metadata/field.rb +110 -0
- data/lib/berkeley_library/av/metadata/fields.rb +130 -0
- data/lib/berkeley_library/av/metadata/link.rb +28 -0
- data/lib/berkeley_library/av/metadata/readers/alma.rb +54 -0
- data/lib/berkeley_library/av/metadata/readers/base.rb +53 -0
- data/lib/berkeley_library/av/metadata/readers/tind.rb +52 -0
- data/lib/berkeley_library/av/metadata/readers.rb +2 -0
- data/lib/berkeley_library/av/metadata/source.rb +93 -0
- data/lib/berkeley_library/av/metadata/tind_html_metadata_da.json +2076 -0
- data/lib/berkeley_library/av/metadata/value.rb +121 -0
- data/lib/berkeley_library/av/metadata.rb +103 -0
- data/lib/berkeley_library/av/record.rb +86 -0
- data/lib/berkeley_library/av/record_id.rb +121 -0
- data/lib/berkeley_library/av/record_not_found.rb +7 -0
- data/lib/berkeley_library/av/restrictions.rb +36 -0
- data/lib/berkeley_library/av/track.rb +132 -0
- data/lib/berkeley_library/av/types/duration.rb +67 -0
- data/lib/berkeley_library/av/types/file_type.rb +84 -0
- data/lib/berkeley_library/av/util.rb +65 -0
- data/rakelib/bundle.rake +8 -0
- data/rakelib/coverage.rake +11 -0
- data/rakelib/gem.rake +54 -0
- data/rakelib/rubocop.rake +18 -0
- data/rakelib/spec.rake +12 -0
- data/spec/.rubocop.yml +116 -0
- data/spec/data/10.23.19.JessieLaCavalier.02.mrc +3 -0
- data/spec/data/alma/991005939359706532-sru.xml +123 -0
- data/spec/data/alma/991034756419706532-sru.xml +162 -0
- data/spec/data/alma/991047179369706532-sru.xml +210 -0
- data/spec/data/alma/991054360089706532-sru.xml +186 -0
- data/spec/data/alma/b11082434-sru.xml +165 -0
- data/spec/data/alma/b18538031-sru.xml +123 -0
- data/spec/data/alma/b20786580-sru.xml +123 -0
- data/spec/data/alma/b22139647-sru.xml +171 -0
- data/spec/data/alma/b22139658-sru.xml +282 -0
- data/spec/data/alma/b23161018-sru.xml +182 -0
- data/spec/data/alma/b23305522-sru.xml +144 -0
- data/spec/data/alma/b24071548-sru.xml +136 -0
- data/spec/data/alma/b24659129-sru.xml +210 -0
- data/spec/data/alma/b25207857-sru.xml +217 -0
- data/spec/data/alma/b25716973-sru.xml +186 -0
- data/spec/data/alma/b25742488-sru.xml +246 -0
- data/spec/data/record-(cityarts)00002.xml +78 -0
- data/spec/data/record-(cityarts)00773.xml +94 -0
- data/spec/data/record-(clir)00020.xml +153 -0
- data/spec/data/record-(miscmat)00615.xml +45 -0
- data/spec/data/record-(pacradio)00107.xml +85 -0
- data/spec/data/record-(pacradio)01469.xml +82 -0
- data/spec/data/record-empty-result.xml +4 -0
- data/spec/data/record-multiple-998s-disordered.xml +178 -0
- data/spec/data/record-multiple-998s.xml +178 -0
- data/spec/data/record-physcolloquia-bk00169017b.xml +78 -0
- data/spec/data/record-ragged-998-subfields.xml +122 -0
- data/spec/data/record-ragged-998s-multiple-fields.xml +160 -0
- data/spec/data/record-redirect-to-login.html +288 -0
- data/spec/data/record_id/bibs_with_check_digits.txt +151 -0
- data/spec/data/search-1993.xml +158 -0
- data/spec/data/search-b23305516.xml +81 -0
- data/spec/lib/berkeley_library/av/av_spec.rb +12 -0
- data/spec/lib/berkeley_library/av/config_spec.rb +250 -0
- data/spec/lib/berkeley_library/av/marc/util_spec.rb +150 -0
- data/spec/lib/berkeley_library/av/marc_spec.rb +62 -0
- data/spec/lib/berkeley_library/av/metadata/field_spec.rb +81 -0
- data/spec/lib/berkeley_library/av/metadata/fields_spec.rb +180 -0
- data/spec/lib/berkeley_library/av/metadata/metadata_spec.rb +274 -0
- data/spec/lib/berkeley_library/av/metadata/source_spec.rb +261 -0
- data/spec/lib/berkeley_library/av/metadata/value_spec.rb +29 -0
- data/spec/lib/berkeley_library/av/record_id_spec.rb +72 -0
- data/spec/lib/berkeley_library/av/record_spec.rb +284 -0
- data/spec/lib/berkeley_library/av/track_spec.rb +335 -0
- data/spec/lib/berkeley_library/av/types/duration_spec.rb +91 -0
- data/spec/lib/berkeley_library/av/types/file_type_spec.rb +98 -0
- data/spec/lib/berkeley_library/av/util_spec.rb +30 -0
- data/spec/spec_helper.rb +63 -0
- metadata +499 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'typesafe_enum'
|
3
|
+
require 'berkeley_library/av/config'
|
4
|
+
require 'berkeley_library/av/constants'
|
5
|
+
require 'berkeley_library/av/record_not_found'
|
6
|
+
require 'berkeley_library/av/marc'
|
7
|
+
require 'berkeley_library/av/util'
|
8
|
+
require 'berkeley_library/av/metadata/readers'
|
9
|
+
|
10
|
+
module BerkeleyLibrary
|
11
|
+
module AV
|
12
|
+
class Metadata
|
13
|
+
class Source < TypesafeEnum::Base
|
14
|
+
include AV::Constants
|
15
|
+
|
16
|
+
new(:ALMA) { singleton_class.include(Readers::Alma) }
|
17
|
+
new(:TIND) { singleton_class.include(Readers::TIND) }
|
18
|
+
|
19
|
+
LINK_TEXT_ALMA = 'View library catalog record.'.freeze # TODO: is this right?
|
20
|
+
LINK_TEXT_TIND = 'View record in Digital Collections.'.freeze
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def for_record_id(record_id)
|
24
|
+
id_type = RecordId.ensure_record_id(record_id).type
|
25
|
+
return ALMA if [RecordId::Type::ALMA, RecordId::Type::MILLENNIUM].include?(id_type)
|
26
|
+
|
27
|
+
TIND
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def name
|
32
|
+
key.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
def catalog_link_text
|
36
|
+
return LINK_TEXT_ALMA if self == ALMA
|
37
|
+
return LINK_TEXT_TIND if self == TIND
|
38
|
+
end
|
39
|
+
|
40
|
+
def display_uri_for(metadata)
|
41
|
+
record_id = canonical_record_id_for(metadata)
|
42
|
+
raise ArgumentError, "#{self}: unable to determine record ID from metadata #{metadata.inspect}" unless record_id
|
43
|
+
|
44
|
+
_display_uri_for(record_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
def find_bib_number(metadata)
|
48
|
+
return alma_bib_number(metadata.marc_record) if self == Source::ALMA
|
49
|
+
return tind_bib_number(metadata.marc_record) if self == Source::TIND
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def canonical_record_id_for(metadata)
|
55
|
+
accessor = canonical_record_id_accessor
|
56
|
+
metadata.send(accessor) if metadata.respond_to?(accessor)
|
57
|
+
end
|
58
|
+
|
59
|
+
def canonical_record_id_accessor
|
60
|
+
return :alma_id if self == ALMA
|
61
|
+
return :tind_id if self == TIND
|
62
|
+
end
|
63
|
+
|
64
|
+
def tind_bib_number(marc_record)
|
65
|
+
tag = TAG_TIND_CATALOG_ID
|
66
|
+
code = SUBFIELD_CODE_TIND_BIB_NUMBER
|
67
|
+
bib_from_marc(marc_record, tag, code)
|
68
|
+
end
|
69
|
+
|
70
|
+
def alma_bib_number(marc_record)
|
71
|
+
tag = TAG_ALMA_MIGRATION_INFO
|
72
|
+
code = SUBFIELD_CODE_ALMA_BIB_NUMBER
|
73
|
+
bib_from_marc(marc_record, tag, code)
|
74
|
+
end
|
75
|
+
|
76
|
+
def bib_from_marc(marc_record, tag, code)
|
77
|
+
return unless (bib_number = find_subfield_value(marc_record, tag, code))
|
78
|
+
return unless RecordId::Type.for_id(bib_number) == RecordId::Type::MILLENNIUM
|
79
|
+
|
80
|
+
RecordId.strip_check_digit(bib_number)
|
81
|
+
end
|
82
|
+
|
83
|
+
# TODO: Use marc/spec
|
84
|
+
def find_subfield_value(marc_record, tag, code)
|
85
|
+
marc_record.fields(tag).filter_map do |df|
|
86
|
+
subfield = df.find { |sf| sf.code == code }
|
87
|
+
subfield.value if subfield
|
88
|
+
end.first
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|