Sha256: f2ee0a67d5c21dbb08ea660995a948005ab582f0d728456f6461bc58850d439b

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

module Exlibris
  module Aleph
    class Patron
      class Record
        class Item
          attr_reader :patron_id, :record_id, :id

          def initialize(patron_id, record_id, id)
            @patron_id = patron_id
            @record_id = record_id
            @id = id
          end

          def item
            @item ||= Aleph::Item.new(record_id, id).tap do |item|
              client = self.send(:client)
              root = self.send(:root)
              reader = self.send(:reader)
              item.instance_eval { instance_variable_set(:@client, client) }
              item.instance_eval { instance_variable_set(:@root, root) }
              item.instance_eval { instance_variable_set(:@reader, reader) }
            end
          end

          def circulation_policy
            @circulation_policy ||=
              CirculationPolicy.new(privileges, *pickup_locations)
          end

          def hold
            @hold ||= Hold.new(patron_id, record_id, id)
          end

          def create_hold(parameters)
            CreateHold.new(patron_id, record_id, id, parameters)
          end

          private
          def privileges
            @privileges ||= CirculationPolicy::Privileges.new(reader)
          end

          def pickup_locations
            @pickup_locations ||= reader.pickup_locations
          end

          def client
            @client ||=
              API::Client::Patron::Record::Item.new(patron_id, record_id, id)
          end

          def root
            @root ||= client.root
          end

          def reader
            @reader ||= API::Reader::Patron::Record::Item.new(root)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
exlibris-aleph-2.0.4 lib/exlibris/aleph/patron/record/item.rb
exlibris-aleph-2.0.3 lib/exlibris/aleph/patron/record/item.rb
exlibris-aleph-2.0.0 lib/exlibris/aleph/patron/record/item.rb