Sha256: ed22567c6ba8b7dbd8d76859b873587df88e5f6db76236e0d17a2e68f7e12f54

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

# TODO: 'https://duldev.atlassian.net/browse/DDR-1755'

module Ddr
  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

1 entries across 1 versions & 1 rubygems

Version Path
ddr-core-1.0.0 app/models/ddr/finding_aid.rb