Module: BerkeleyLibrary::Alma::RecordId
- Extended by:
- Constants
- Includes:
- Constants, Logging, Util, Comparable
- Defined in:
- lib/berkeley_library/alma/record_id.rb
Overview
Encapsulates an ID that can be used to look up records in Alma via SRU.
Constant Summary
Constants included from Constants
Constants::ALMA_RECORD_RE, Constants::DEFAULT_USER_AGENT, Constants::MILLENNIUM_RECORD_RE
Class Method Summary collapse
-
.parse(id) ⇒ RecordId?
Parses a string record ID and returns a RecordId object.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compares this RecordId with another based on their string representations.
-
#get_marc_record ⇒ MARC::Record?
Makes an SRU query for this record and returns a MARC record, or nil if the record is not found.
-
#get_marc_xml ⇒ String?
Makes an SRU query for this record and returns the XML query response as a string.
-
#marc_uri ⇒ URI
Returns a URI for retrieving MARCXML from this record via SRU.
Class Method Details
.parse(id) ⇒ RecordId?
Parses a string record ID and returns a BerkeleyLibrary::Alma::RecordId object. For convenience, also accepts a BerkeleyLibrary::Alma::RecordId and simply returns it, so it can be used in situations where it may not be clear whether the ID has already been parsed.
Note: Use the BarCode class for barcodes, which don't have a consistent format and hence can't be auto-detected.
34 35 36 37 38 39 40 |
# File 'lib/berkeley_library/alma/record_id.rb', line 34 def parse(id) # noinspection RubyMismatchedReturnType return id if id.is_a?(RecordId) return MMSID.new(id) if ALMA_RECORD_RE =~ id return BibNumber.new(id) if MILLENNIUM_RECORD_RE =~ id end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compares this BerkeleyLibrary::Alma::RecordId with another based on their string representations.
86 87 88 89 90 91 92 |
# File 'lib/berkeley_library/alma/record_id.rb', line 86 def <=>(other) return 0 if equal?(other) return unless other return unless other.is_a?(RecordId) to_s <=> other.to_s end |
#get_marc_record ⇒ MARC::Record?
Makes an SRU query for this record and returns a MARC record, or nil if the record is not found.
Note that in the event the SRU query finds multiple records, only the first record is returned.
rubocop:disable Naming/AccessorMethodName
62 63 64 65 66 |
# File 'lib/berkeley_library/alma/record_id.rb', line 62 def get_marc_record records = SRU.marc_records_for(sru_query_value, max_records: 1) logger.warn("GET #{marc_uri} did not return a MARC record") unless (marc_record = records.first) marc_record end |
#get_marc_xml ⇒ String?
Makes an SRU query for this record and returns the XML query response as a string.
rubocop:disable Naming/AccessorMethodName
74 75 76 |
# File 'lib/berkeley_library/alma/record_id.rb', line 74 def get_marc_xml SRU.make_sru_query(sru_query_value, max_records: 1) end |
#marc_uri ⇒ URI
Returns a URI for retrieving MARCXML from this record via SRU. Requires Config.alma_sru_base_uri to be set.
50 51 52 |
# File 'lib/berkeley_library/alma/record_id.rb', line 50 def marc_uri SRU.sru_query_uri(sru_query_value, max_records: 1) end |