berkeley_library-av-core 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +391 -0
  3. data/.github/workflows/build.yml +30 -0
  4. data/.gitignore +388 -0
  5. data/.idea/av_core.iml +146 -0
  6. data/.idea/codeStyles/Project.xml +12 -0
  7. data/.idea/codeStyles/codeStyleConfig.xml +5 -0
  8. data/.idea/go.imports.xml +6 -0
  9. data/.idea/inspectionProfiles/Project_Default.xml +37 -0
  10. data/.idea/misc.xml +6 -0
  11. data/.idea/modules.xml +8 -0
  12. data/.idea/vcs.xml +6 -0
  13. data/.rubocop.yml +241 -0
  14. data/.ruby-version +1 -0
  15. data/.simplecov +8 -0
  16. data/CHANGES.md +38 -0
  17. data/Gemfile +3 -0
  18. data/Jenkinsfile +16 -0
  19. data/LICENSE.md +21 -0
  20. data/README.md +20 -0
  21. data/Rakefile +20 -0
  22. data/av_core.gemspec +49 -0
  23. data/lib/berkeley_library/av/config.rb +238 -0
  24. data/lib/berkeley_library/av/constants.rb +30 -0
  25. data/lib/berkeley_library/av/core/module_info.rb +18 -0
  26. data/lib/berkeley_library/av/core.rb +7 -0
  27. data/lib/berkeley_library/av/marc/util.rb +114 -0
  28. data/lib/berkeley_library/av/marc.rb +52 -0
  29. data/lib/berkeley_library/av/metadata/README.md +5 -0
  30. data/lib/berkeley_library/av/metadata/field.rb +110 -0
  31. data/lib/berkeley_library/av/metadata/fields.rb +130 -0
  32. data/lib/berkeley_library/av/metadata/link.rb +28 -0
  33. data/lib/berkeley_library/av/metadata/readers/alma.rb +54 -0
  34. data/lib/berkeley_library/av/metadata/readers/base.rb +53 -0
  35. data/lib/berkeley_library/av/metadata/readers/tind.rb +52 -0
  36. data/lib/berkeley_library/av/metadata/readers.rb +2 -0
  37. data/lib/berkeley_library/av/metadata/source.rb +93 -0
  38. data/lib/berkeley_library/av/metadata/tind_html_metadata_da.json +2076 -0
  39. data/lib/berkeley_library/av/metadata/value.rb +121 -0
  40. data/lib/berkeley_library/av/metadata.rb +103 -0
  41. data/lib/berkeley_library/av/record.rb +86 -0
  42. data/lib/berkeley_library/av/record_id.rb +121 -0
  43. data/lib/berkeley_library/av/record_not_found.rb +7 -0
  44. data/lib/berkeley_library/av/restrictions.rb +36 -0
  45. data/lib/berkeley_library/av/track.rb +132 -0
  46. data/lib/berkeley_library/av/types/duration.rb +67 -0
  47. data/lib/berkeley_library/av/types/file_type.rb +84 -0
  48. data/lib/berkeley_library/av/util.rb +65 -0
  49. data/rakelib/bundle.rake +8 -0
  50. data/rakelib/coverage.rake +11 -0
  51. data/rakelib/gem.rake +54 -0
  52. data/rakelib/rubocop.rake +18 -0
  53. data/rakelib/spec.rake +12 -0
  54. data/spec/.rubocop.yml +116 -0
  55. data/spec/data/10.23.19.JessieLaCavalier.02.mrc +3 -0
  56. data/spec/data/alma/991005939359706532-sru.xml +123 -0
  57. data/spec/data/alma/991034756419706532-sru.xml +162 -0
  58. data/spec/data/alma/991047179369706532-sru.xml +210 -0
  59. data/spec/data/alma/991054360089706532-sru.xml +186 -0
  60. data/spec/data/alma/b11082434-sru.xml +165 -0
  61. data/spec/data/alma/b18538031-sru.xml +123 -0
  62. data/spec/data/alma/b20786580-sru.xml +123 -0
  63. data/spec/data/alma/b22139647-sru.xml +171 -0
  64. data/spec/data/alma/b22139658-sru.xml +282 -0
  65. data/spec/data/alma/b23161018-sru.xml +182 -0
  66. data/spec/data/alma/b23305522-sru.xml +144 -0
  67. data/spec/data/alma/b24071548-sru.xml +136 -0
  68. data/spec/data/alma/b24659129-sru.xml +210 -0
  69. data/spec/data/alma/b25207857-sru.xml +217 -0
  70. data/spec/data/alma/b25716973-sru.xml +186 -0
  71. data/spec/data/alma/b25742488-sru.xml +246 -0
  72. data/spec/data/record-(cityarts)00002.xml +78 -0
  73. data/spec/data/record-(cityarts)00773.xml +94 -0
  74. data/spec/data/record-(clir)00020.xml +153 -0
  75. data/spec/data/record-(miscmat)00615.xml +45 -0
  76. data/spec/data/record-(pacradio)00107.xml +85 -0
  77. data/spec/data/record-(pacradio)01469.xml +82 -0
  78. data/spec/data/record-empty-result.xml +4 -0
  79. data/spec/data/record-multiple-998s-disordered.xml +178 -0
  80. data/spec/data/record-multiple-998s.xml +178 -0
  81. data/spec/data/record-physcolloquia-bk00169017b.xml +78 -0
  82. data/spec/data/record-ragged-998-subfields.xml +122 -0
  83. data/spec/data/record-ragged-998s-multiple-fields.xml +160 -0
  84. data/spec/data/record-redirect-to-login.html +288 -0
  85. data/spec/data/record_id/bibs_with_check_digits.txt +151 -0
  86. data/spec/data/search-1993.xml +158 -0
  87. data/spec/data/search-b23305516.xml +81 -0
  88. data/spec/lib/berkeley_library/av/av_spec.rb +12 -0
  89. data/spec/lib/berkeley_library/av/config_spec.rb +250 -0
  90. data/spec/lib/berkeley_library/av/marc/util_spec.rb +150 -0
  91. data/spec/lib/berkeley_library/av/marc_spec.rb +62 -0
  92. data/spec/lib/berkeley_library/av/metadata/field_spec.rb +81 -0
  93. data/spec/lib/berkeley_library/av/metadata/fields_spec.rb +180 -0
  94. data/spec/lib/berkeley_library/av/metadata/metadata_spec.rb +274 -0
  95. data/spec/lib/berkeley_library/av/metadata/source_spec.rb +261 -0
  96. data/spec/lib/berkeley_library/av/metadata/value_spec.rb +29 -0
  97. data/spec/lib/berkeley_library/av/record_id_spec.rb +72 -0
  98. data/spec/lib/berkeley_library/av/record_spec.rb +284 -0
  99. data/spec/lib/berkeley_library/av/track_spec.rb +335 -0
  100. data/spec/lib/berkeley_library/av/types/duration_spec.rb +91 -0
  101. data/spec/lib/berkeley_library/av/types/file_type_spec.rb +98 -0
  102. data/spec/lib/berkeley_library/av/util_spec.rb +30 -0
  103. data/spec/spec_helper.rb +63 -0
  104. 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