Class: BerkeleyLibrary::AV::RecordId
- Inherits:
-
Object
- Object
- BerkeleyLibrary::AV::RecordId
- Extended by:
- Constants
- Includes:
- Util, Comparable
- Defined in:
- lib/berkeley_library/av/record_id.rb
Defined Under Namespace
Classes: Type
Constant Summary
Constants included from Constants
Constants::ALMA_RECORD_RE, Constants::MILLENNIUM_RECORD_RE, Constants::OCLC_RECORD_RE, Constants::SUBFIELD_CODES_TRACKS, Constants::SUBFIELD_CODE_ALMA_BIB_NUMBER, Constants::SUBFIELD_CODE_DURATION, Constants::SUBFIELD_CODE_LINKTEXT, Constants::SUBFIELD_CODE_PATH, Constants::SUBFIELD_CODE_TIND_BIB_NUMBER, Constants::SUBFIELD_CODE_TITLE, Constants::SUBFIELD_CODE_URI, Constants::TAG_ALMA_MIGRATION_INFO, Constants::TAG_LINK_FIELD, Constants::TAG_TIND_CATALOG_ID, Constants::TAG_TIND_ID, Constants::TAG_TITLE_FIELD, Constants::TAG_TRACK_FIELD, Constants::TAG_TRANSCRIPT_FIELD, Constants::UNKNOWN_TITLE
Constants included from Util
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
———————————————————— Fields.
-
#type ⇒ Object
readonly
———————————————————— Fields.
Class Method Summary collapse
- .ensure_check_digit(bib_number) ⇒ Object
- .ensure_record_id(record_id) ⇒ Object
- .strip_check_digit(bib_number) ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
———————————————————— Comparable.
-
#hash ⇒ Object
———————————————————— Object overrides.
-
#initialize(id) ⇒ RecordId
constructor
———————————————————— Initializer.
- #inspect ⇒ Object
- #to_s ⇒ Object
Methods included from Util
#class_name, #compare_by_attributes, #compare_values, #do_get, #tidy_value
Constructor Details
Instance Attribute Details
#id ⇒ Object (readonly)
Fields
14 15 16 |
# File 'lib/berkeley_library/av/record_id.rb', line 14 def id @id end |
#type ⇒ Object (readonly)
Fields
14 15 16 |
# File 'lib/berkeley_library/av/record_id.rb', line 14 def type @type end |
Class Method Details
.ensure_check_digit(bib_number) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/berkeley_library/av/record_id.rb', line 36 def ensure_check_digit(bib_number) digit_str, check_str = split_bib(bib_number) digits = digit_str.chars.map(&:to_i) check_digit = calculate_check_digit(digits) return "b#{digit_str}#{check_digit}" if check_str.nil? || check_str == 'a' return bib_number if check_str == check_digit raise ArgumentError, "#{bib_number} check digit invalid: expected #{check_digit}, got #{check_str}" end |
.ensure_record_id(record_id) ⇒ Object
30 31 32 33 34 |
# File 'lib/berkeley_library/av/record_id.rb', line 30 def ensure_record_id(record_id) return record_id if record_id.is_a?(RecordId) RecordId.new(record_id) end |
.strip_check_digit(bib_number) ⇒ Object
48 49 50 51 |
# File 'lib/berkeley_library/av/record_id.rb', line 48 def strip_check_digit(bib_number) digit_str, = split_bib(bib_number) "b#{digit_str}" end |
Instance Method Details
#<=>(other) ⇒ Object
Comparable
73 74 75 |
# File 'lib/berkeley_library/av/record_id.rb', line 73 def <=>(other) compare_by_attributes(self, other, :id, :type) end |
#hash ⇒ Object
Object overrides
80 81 82 |
# File 'lib/berkeley_library/av/record_id.rb', line 80 def hash [id, type].hash end |
#inspect ⇒ Object
88 89 90 |
# File 'lib/berkeley_library/av/record_id.rb', line 88 def inspect "#{self.class}(#{id} [#{type}])@#{object_id}" end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/berkeley_library/av/record_id.rb', line 84 def to_s id end |