module NewspaperWorks::Ingest::NDNP::NDNPMetsHelper

Mixin for mets-specific XPath and traversal of issue/page data

Constants

XML_NS

Public Instance Methods

container() click to toggle source
# File lib/newspaper_works/ingest/ndnp/ndnp_mets_helper.rb, line 62
def container
  reel_path = container_path
  return unless File.exist?(reel_path)
  NewspaperWorks::Ingest::NDNP::ContainerIngest.new(reel_path)
end
container_path() click to toggle source
# File lib/newspaper_works/ingest/ndnp/ndnp_mets_helper.rb, line 56
def container_path
  reel_dir = File.expand_path('..', File.dirname(path))
  reel_base = File.basename(reel_dir)
  File.join(reel_dir, "#{reel_base}_1.xml")
end
dmd_node() click to toggle source
# File lib/newspaper_works/ingest/ndnp/ndnp_mets_helper.rb, line 26
def dmd_node
  xpath("//mets:dmdSec[@ID='#{dmdid}']")
end
normalize_path(specified_path) click to toggle source
# File lib/newspaper_works/ingest/ndnp/ndnp_mets_helper.rb, line 30
def normalize_path(specified_path)
  return specified_path if specified_path.start_with?('/')
  basename = File.dirname(path)
  File.join(basename, specified_path)
end
page_files() click to toggle source

returns hash of “use” key string to path value

# File lib/newspaper_works/ingest/ndnp/ndnp_mets_helper.rb, line 37
def page_files
  # get pointers from structmap:
  file_group = xpath("//mets:structMap//mets:div[@DMDID='#{dmdid}']")
  result = xpath('mets:fptr', file_group).map do |fptr|
    file_id = fptr['FILEID']
    file_node = xpath(
      "//mets:fileSec//mets:fileGrp//mets:file[@ID='#{file_id}']"
    ).first
    [
      file_node['USE'],
      xpath('mets:FLocat', file_node).first.attribute_with_ns(
        'href',
        'http://www.w3.org/1999/xlink'
      ).to_s
    ]
  end
  result.to_h
end
xpath(expr, context = nil) click to toggle source

DRY XPath without repeatedly specifying default namespace urlmap

# File lib/newspaper_works/ingest/ndnp/ndnp_mets_helper.rb, line 18
def xpath(expr, context = nil)
  context ||= doc
  context.xpath(
    expr,
    **XML_NS
  )
end