lib/stanford-mods/searchworks.rb in stanford-mods-0.0.8 vs lib/stanford-mods/searchworks.rb in stanford-mods-0.0.9
- old
+ new
@@ -120,11 +120,11 @@
# Values are the contents of:
# subject/geographic
# subject/hierarchicalGeographic
# subject/geographicCode (only include the translated value if it isn't already present from other mods geo fields)
# @param [String] sep - the separator string for joining hierarchicalGeographic sub elements
- # @return [Array<String>] values for geographic_search Solr field for this document or nil if none
+ # @return [Array<String>] values for geographic_search Solr field for this document or [] if none
def sw_geographic_search(sep = ' ')
result = term_values([:subject, :geographic]) || []
# hierarchicalGeographic has sub elements
@mods_ng_xml.subject.hierarchicalGeographic.each { |hg_node|
@@ -140,11 +140,37 @@
trans_code_vals.each { |val|
result << val if !result.include?(val)
}
end
- return nil if result.empty?
result
+ end
+
+ # Values are the contents of:
+ # subject/name/namePart
+ # "Values from namePart subelements should be concatenated in the order they appear (e.g. "Shakespeare, William, 1564-1616")"
+ # @param [String] sep - the separator string for joining namePart sub elements
+ # @return [Array<String>] values for names inside subject elements or [] if none
+ def sw_subject_names(sep = ', ')
+ result = []
+ @mods_ng_xml.subject.name_el.select { |n_el| n_el.namePart }.each { |name_el_w_np|
+ parts = name_el_w_np.namePart.map { |npn| npn.text unless npn.text.empty? }.compact
+ result << parts.join(sep).strip unless parts.empty?
+ }
+ result
+ end
+
+ # Values are the contents of:
+ # subject/titleInfo/(subelements)
+ # @param [String] sep - the separator string for joining titleInfo sub elements
+ # @return [Array<String>] values for titles inside subject elements or [] if none
+ def sw_subject_titles(sep = ' ')
+ result = []
+ @mods_ng_xml.subject.titleInfo.each { |ti_el|
+ parts = ti_el.element_children.map { |el| el.text unless el.text.empty? }.compact
+ result << parts.join(sep).strip unless parts.empty?
+ }
+ result
end
end # class Record
end # Module Mods
end # Module Stanford