Module: BerkeleyLibrary::Alma::RecordId

Extended by:
Constants
Includes:
Constants, Logging, Util, Comparable
Included in:
BarCode, BibNumber, MMSID
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

Instance Method Summary collapse

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.

Parameters:

  • id (String, RecordId)

    the ID to parse

Returns:

  • (RecordId, nil)

    an MMSID or BibNumber, depending on the type of ID, or nil if the specified id is neither an MMS ID nor a bib number

Raises:

  • (ArgumentError)

    if the specified string is a correctly formatted Millennium bib number, but has an incorrect check digit



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.

Returns:

  • (Integer, nil)

See Also:

  • Comparable#<=>


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_recordMARC::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

Returns:

  • (MARC::Record, nil)

    the MARC record



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_xmlString?

Makes an SRU query for this record and returns the XML query response as a string.

rubocop:disable Naming/AccessorMethodName

Returns:

  • (String, nil)

    the SRU query response body, or nil in the event of an error.



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_uriURI

Returns a URI for retrieving MARCXML from this record via SRU. Requires Config.alma_sru_base_uri to be set.

Returns:

  • (URI)

    the MARC URI



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