Module: NEU::MODS::Selectors
- Includes:
- Projection::NameDisplay, Projection::Support
- Included in:
- Document, Projection::Access, Projection::Names, Projection::Subjects, Projection::Titles
- Defined in:
- lib/neu/mods/selectors.rb
Overview
Node LOCATION, returning live nodes that serve both the read path and Cerberus's MODSMerge edits. A selector must never return a node the projection would not read from. See docs/editing.md.
Constant Summary
Constants included from Projection::Support
Projection::Support::AUTHORITY_ATTRIBUTES
Instance Method Summary collapse
-
#abstract_nodes ⇒ Object
All top-level
elements (MODS permits several). -
#editable_creator_nodes(type) ⇒ Object
The plain Creator
nodes of one @type, for replace-on-save. -
#keyword_subjects ⇒ Object
The attribute-free, topic-only subjects the simple form manages.
-
#primary_title_info ⇒ Object
Top-level primary titleInfo, falling back to the first top-level one that is not a variant; nil if every titleInfo is a variant.
-
#variant_title?(node) ⇒ Boolean
Any @type marks a variant: MODS enumerates four types, all variants.
Instance Method Details
#abstract_nodes ⇒ Object
All top-level
32 33 34 |
# File 'lib/neu/mods/selectors.rb', line 32 def abstract_nodes doc.xpath("/mods:mods/mods:abstract", NAMESPACE) end |
#editable_creator_nodes(type) ⇒ Object
The plain Creator
42 43 44 45 |
# File 'lib/neu/mods/selectors.rb', line 42 def editable_creator_nodes(type) doc.xpath("/mods:mods/mods:name[@type='#{type}']", NAMESPACE) .select { |n| editable_creator_name?(n) } end |
#keyword_subjects ⇒ Object
The attribute-free, topic-only subjects the simple form manages.
37 38 39 |
# File 'lib/neu/mods/selectors.rb', line 37 def keyword_subjects doc.xpath("/mods:mods/mods:subject", NAMESPACE).select { |s| keyword_subject?(s) } end |
#primary_title_info ⇒ Object
Top-level primary titleInfo, falling back to the first top-level one that is not a variant; nil if every titleInfo is a variant. Never fall back to a variant: MODSMerge overwrites the node this returns. See docs/titles.md.
21 22 23 24 |
# File 'lib/neu/mods/selectors.rb', line 21 def primary_title_info doc.at_xpath("/mods:mods/mods:titleInfo[@usage='primary']", NAMESPACE) || doc.xpath("/mods:mods/mods:titleInfo", NAMESPACE).reject { |ti| variant_title?(ti) }.first end |
#variant_title?(node) ⇒ Boolean
Any @type marks a variant: MODS enumerates four types, all variants.
27 28 29 |
# File 'lib/neu/mods/selectors.rb', line 27 def variant_title?(node) !attr_value(node, "type").nil? end |