Sha256: 590ef6a5f5e21255aa5960c6872a2f55f2819b8f677d216255f3075bfd73d02c

Contents?: true

Size: 972 Bytes

Versions: 2

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

module DigitalScriptorium
  # Represents a meta record consisting of a manuscript, its holding information, and metadata record.
  class DsMeta
    include ItemId
    include PropertyId

    attr_reader :holding, :manuscript, :record

    def initialize(record, export_hash)
      manuscript = export_hash[record.described_manuscript_id]
      current_holdings = current_holdings(manuscript, export_hash)

      if current_holdings.size != 1
        raise "Manuscripts must have exactly 1 current holding, found #{current_holdings.size}"
      end

      @holding = current_holdings.first
      @manuscript = manuscript
      @record = record
    end

    def current?(holding)
      holding.holding_status == HOLDING_STATUS_CURRENT
    end

    def current_holdings(manuscript, export_hash)
      manuscript.holding_ids
                .map { |id| export_hash[id] }
                .filter { |holding| current?(holding) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
digital_scriptorium-0.2.1 lib/digital_scriptorium/ds_meta.rb
digital_scriptorium-0.2.0 lib/digital_scriptorium/ds_meta.rb