class NewspaperWorks::Ingest::NDNP::BatchXMLIngest

Attributes

container_paths[RW]
issue_paths[RW]
path[RW]

Public Class Methods

new(path) click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 14
def initialize(path)
  @path = path
  load_doc
  @container_paths = xpath('//ndnp:batch//ndnp:reel').map do |e|
    normalize_path(e.text)
  end
  @issue_paths = xpath('//ndnp:batch//ndnp:issue').map do |e|
    normalize_path(e.text)
  end
end

Public Instance Methods

containers() click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 38
def containers
  container_paths.map { |path| get(path) }
end
each() { |get_issue(path)| ... } click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 42
def each
  @issue_paths.each do |path|
    yield get_issue(path)
  end
end
get(path) click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 29
def get(path)
  return get_issue(path) if issue_paths.include?(path)
  get_container(path)
end
issues() click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 34
def issues
  issue_paths.map { |path| get(path) }
end
name() click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 25
def name
  xpath('//ndnp:batch').first.attributes['name'].value
end

Private Instance Methods

get_container(path) click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 54
def get_container(path)
  NewspaperWorks::Ingest::NDNP::ContainerIngest.new(path)
end
get_issue(path) click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 50
def get_issue(path)
  NewspaperWorks::Ingest::NDNP::IssueIngest.new(path)
end
load_doc() click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 66
def load_doc
  @doc = Nokogiri::XML(File.open(path))
end
xpath(expr) click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_xml_ingest.rb, line 58
def xpath(expr)
  ns = {
    ndnp: 'http://www.loc.gov/ndnp',
    NDNP: 'http://www.loc.gov/ndnp'
  }
  @doc.xpath(expr, **ns)
end