Sha256: a5e4cb49f3533f2e9334aaf12a39a47651a6b139e09d43d7cc69f6c0aa075575

Contents?: true

Size: 1.3 KB

Versions: 91

Compression:

Stored size: 1.3 KB

Contents

require "nokogiri"

module Ddr::Models
  class FindingAid

    attr_reader :ead_id

    EAD_XMLNS = "urn:isbn:1-931666-22-9"

    def initialize(ead_id)
      @ead_id = ead_id
    end

    def url
      doc.css("eadid").attr("url").text
    end

    # The finding aid title
    def title
      doc.css("titleproper").children.first.text.strip
    end

    def repository
      collection.xpath('ead:did/ead:repository/ead:corpname', ead: EAD_XMLNS).text
    end

    def collection_date_span
      collection.xpath('ead:did/ead:unitdate[@type="inclusive"]', ead: EAD_XMLNS).text
    end

    def collection_number
      collection.xpath('ead:did/ead:unitid', ead: EAD_XMLNS).text
    end

    def collection_title
      collection.xpath('ead:did/ead:unittitle', ead: EAD_XMLNS).text
    end

    def extent
      collection.xpath('ead:did/ead:physdesc/ead:extent', ead: EAD_XMLNS).map(&:text).join("; ")
    end

    def abstract
      collection.xpath('ead:did/ead:abstract', ead: EAD_XMLNS).text
    end

    private

    def collection
      doc.xpath('//ead:archdesc[@level="collection"]', ead: EAD_XMLNS)
    end

    # @raise [OpenURI::HTTPError] if 404, etc.
    def doc
      @doc ||= Nokogiri::XML(open(ead_xml_url))
    end

    def ead_xml_url
      Ddr::Models.ead_xml_base_url + ead_id + ".xml"
    end

  end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
ddr-models-2.11.0 lib/ddr/models/finding_aid.rb
ddr-models-2.10.2 lib/ddr/models/finding_aid.rb
ddr-models-2.10.1 lib/ddr/models/finding_aid.rb
ddr-models-2.10.0 lib/ddr/models/finding_aid.rb
ddr-models-2.10.0.rc2 lib/ddr/models/finding_aid.rb
ddr-models-2.10.0.rc1 lib/ddr/models/finding_aid.rb
ddr-models-2.9.2 lib/ddr/models/finding_aid.rb
ddr-models-2.9.1 lib/ddr/models/finding_aid.rb
ddr-models-2.9.0 lib/ddr/models/finding_aid.rb
ddr-models-2.9.0.rc1 lib/ddr/models/finding_aid.rb
ddr-models-2.8.0 lib/ddr/models/finding_aid.rb
ddr-models-2.8.0.rc1 lib/ddr/models/finding_aid.rb
ddr-models-2.7.6 lib/ddr/models/finding_aid.rb
ddr-models-2.7.5 lib/ddr/models/finding_aid.rb
ddr-models-2.7.4 lib/ddr/models/finding_aid.rb
ddr-models-2.7.3 lib/ddr/models/finding_aid.rb
ddr-models-2.7.2 lib/ddr/models/finding_aid.rb
ddr-models-2.7.1 lib/ddr/models/finding_aid.rb
ddr-models-2.7.0 lib/ddr/models/finding_aid.rb
ddr-models-2.7.0.rc1 lib/ddr/models/finding_aid.rb