Sha256: fcf28ac54d044357f83727d3f3b94362f935a579e3f0cbae41463fb384cd75b7

Contents?: true

Size: 983 Bytes

Versions: 1

Compression:

Stored size: 983 Bytes

Contents

require "nokogiri"
require "skala/adapter/get_record_holdable_items"
require_relative "../aleph_adapter"
require_relative "./get_record_items"

class Skala::AlephAdapter::GetRecordHoldableItems < Skala::Adapter::GetRecordHoldableItems
  def call(document_number, username, options = {})
    get_record_items_result = get_record_items(document_number, options.merge(username: username))

    self.class::Result.new(
      holdable_items: holdable_items(get_record_items_result),
      source: get_record_items_result.source
    )
  end

  private

  def get_record_items(*args)
    adapter.class::GetRecordItems.new(adapter).call(*args) # adapter.class is important to get inherited op
  end

  def holdable_items(get_record_items_result)
    source_doc = Nokogiri::XML(get_record_items_result.source)

    get_record_items_result.items.select do |_item|
      !!source_doc.at_xpath("//item/info[@type='HoldRequest' and contains(@href, _item.id) and @allowed='Y']")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skala-1.1.0 lib/skala/aleph_adapter/get_record_holdable_items.rb