Module: NEU::MODS::Selectors

Included in:
Document
Defined in:
lib/neu/mods/selectors.rb

Overview

Node LOCATION over a parsed MODS document. These return live Nokogiri nodes, so they serve BOTH the read path (projection reads their text) AND the write path (Cerberus’s MODSMerge mutates the returned nodes in place). That shared definition is the point: the node an editor changes is provably the node the projection reads. Mixed into Document; operates on ‘doc`.

Instance Method Summary collapse

Instance Method Details

#abstract_nodesObject

All top-level <abstract> elements (MODS permits several).



20
21
22
# File 'lib/neu/mods/selectors.rb', line 20

def abstract_nodes
  doc.xpath("/mods:mods/mods:abstract", NAMESPACE)
end

#build_node(name, text = nil) ⇒ Object

Build a namespaced MODS element reusing the document’s existing ‘mods:` namespace declaration (so new nodes never re-declare xmlns).



35
36
37
38
39
40
# File 'lib/neu/mods/selectors.rb', line 35

def build_node(name, text = nil)
  node = Nokogiri::XML::Node.new(name, doc)
  node.namespace = doc.root.namespace_definitions.find { |d| d.prefix == "mods" }
  node.content = text unless text.nil?
  node
end

#keyword_subjectsObject

The “keyword” subjects the simple form manages: attribute-free <subject> elements whose element children are all <topic>. Anything with an authority/valueURI (or a non-topic child, e.g. a <name> subject) is curated and left untouched. (Distinct from the projection’s #topical_subjects, which harvests every <topic> for the access copy.)



29
30
31
# File 'lib/neu/mods/selectors.rb', line 29

def keyword_subjects
  doc.xpath("/mods:mods/mods:subject", NAMESPACE).select { |s| keyword_subject?(s) }
end

#primary_title_infoObject

Top-level primary titleInfo, falling back to the first top-level titleInfo. Scoped to direct children of <mods:mods> so a relatedItem’s nested titleInfo (e.g. a series title) is never matched.



14
15
16
17
# File 'lib/neu/mods/selectors.rb', line 14

def primary_title_info
  doc.at_xpath("/mods:mods/mods:titleInfo[@usage='primary']", NAMESPACE) ||
    doc.at_xpath("/mods:mods/mods:titleInfo", NAMESPACE)
end