Class: UWDC::Mods
Overview
Public: Obtain the MODS metadata for a UWDC METS object
Example
# => MODS object fetched from Fedora
# => object constructed from XML file
Instance Attribute Summary
Attributes inherited from Mets
Class Method Summary collapse
-
.attributes ⇒ Object
Public: standardized, supported MODS attributes.
Instance Method Summary collapse
-
#abstracts ⇒ Object
Public: Array of abstracts (sometimes translated) @TODO: support lang here.
-
#access_conditions ⇒ Object
Public: OpenStruct - Terms of Use and Reuse Rights.
-
#dates ⇒ Object
Public: Array of dates.
-
#forms ⇒ Object
Public: Array of forms Example.
-
#metadata ⇒ Object
Public: Access the XML nodes of the METS file.
-
#names ⇒ Object
Public: Array of roles and nameParts.
-
#nodes ⇒ Object
Public: Access the XML nodes of the MODS XML.
-
#related_items ⇒ Object
Public: Array of Structs - Related items’ label and value.
-
#subjects ⇒ Object
Public: Array of subject data.
-
#subjects_heirarchical_geographic ⇒ Object
Public: Array of geographic subject data @TODO: subjects_heirarchical_geographic.
-
#titles ⇒ Object
Public: Array of title data.
-
#valid? ⇒ Boolean
Public: Check MODS for validity @TODO: Use the UWDC MODS Schema.
Methods inherited from Mets
#display, #dublin_core, #file_sec, #initialize, #mods, #origin, #rels_ext, #struct_map, #to_json, #to_ruby, #to_xml
Constructor Details
This class inherits a constructor from UWDC::Mets
Class Method Details
.attributes ⇒ Object
Public: standardized, supported MODS attributes
14 15 16 |
# File 'lib/uwdc/mods.rb', line 14 def self.attributes [:titles, :names, :dates, :forms, :abstracts, :subjects, :related_items] end |
Instance Method Details
#abstracts ⇒ Object
Public: Array of abstracts (sometimes translated) @TODO: support lang here
Example
# => [“The man is an entertainer who captured the wild hyena…”, …]
Returns Array of Strings
106 107 108 |
# File 'lib/uwdc/mods.rb', line 106 def abstracts clean_nodes(nodes.xpath("//mods//abstract")) end |
#access_conditions ⇒ Object
Public: OpenStruct - Terms of Use and Reuse Rights
Example
# => #<OpenStruct rights=[“Delehanty, Jim”], reuse=[“Delehanty, Jim”]>
# => “Delehanty, Jim”
Returns an OpenStruct
142 143 144 |
# File 'lib/uwdc/mods.rb', line 142 def access_conditions OpenStruct.new(rights: rights, reuse: reuse) end |
#dates ⇒ Object
Public: Array of dates
Example
# => [“1985”, …]
Returns Array of Strings
82 83 84 |
# File 'lib/uwdc/mods.rb', line 82 def dates clean_nodes(nodes.xpath("//mods/originInfo//dateIssued")) end |
#forms ⇒ Object
Public: Array of forms Example
# => [“StillImage”, …]
Returns Array of Strings
93 94 95 |
# File 'lib/uwdc/mods.rb', line 93 def forms clean_nodes(nodes.xpath("//mods/physicalDescription//form")) end |
#metadata ⇒ Object
Public: Access the XML nodes of the METS file
Example
# => => [‘A life idyl’, …], …
Returns Hash
38 39 40 41 42 43 44 45 |
# File 'lib/uwdc/mods.rb', line 38 def attributes = UWDC::Mods.attributes.inject({}) do |result, method| result[method] = self.send(method) result end attributes[:access_conditions] = self.access_conditions attributes end |
#names ⇒ Object
Public: Array of roles and nameParts
Example
# => [#<OpenStruct name=“Foo”, role=“Bar”>, …]
# => “Foo”
Returns Array of OpenStructs
70 71 72 |
# File 'lib/uwdc/mods.rb', line 70 def names nodes.xpath("//mods/name").inject([]){|arr,node| arr << capture_name(node); arr} end |
#nodes ⇒ Object
Public: Access the XML nodes of the MODS XML
Example
# => Nokogiri::XML::NodeSet
Returns the Nokogiri::XML::NodeSet for the parsed MODS XML
26 27 28 |
# File 'lib/uwdc/mods.rb', line 26 def nodes @xml.nodes.xpath("//dmdSec[contains(@ID,'#{@id}')]//mods[1]") end |
#related_items ⇒ Object
Public: Array of Structs - Related items’ label and value
Example
# => [#<OpenStruct label=“Part of”, name=“Africa Focus”>, …]
# => “Africa Focus”
Retuns Array of OpenStruct
157 158 159 |
# File 'lib/uwdc/mods.rb', line 157 def nodes.xpath("//mods/relatedItem").inject([]){|arr,node| arr << capture_relation(node) ; arr } end |
#subjects ⇒ Object
Public: Array of subject data
Example
# => [“Delehanty, James”, “Animals”, …]
Returns Array of Strings
118 119 120 |
# File 'lib/uwdc/mods.rb', line 118 def subjects clean_nodes(nodes.xpath("//mods/subject//topic")) end |
#subjects_heirarchical_geographic ⇒ Object
Public: Array of geographic subject data @TODO: subjects_heirarchical_geographic
Example # => [“Foo”, “Bar”, “Baz”]
128 129 |
# File 'lib/uwdc/mods.rb', line 128 def subjects_heirarchical_geographic end |
#titles ⇒ Object
Public: Array of title data
Example
# => [‘A life ldyl’, …]
Returns Array
55 56 57 |
# File 'lib/uwdc/mods.rb', line 55 def titles clean_nodes(nodes.xpath("//mods/titleInfo//title")) end |
#valid? ⇒ Boolean
Public: Check MODS for validity @TODO: Use the UWDC MODS Schema
Example
@mods.valid? # => true
Returns Boolean
170 171 172 173 174 175 |
# File 'lib/uwdc/mods.rb', line 170 def valid? response = http_client.get("http://www.loc.gov/standards/mods/mods.xsd") xsd = Nokogiri::XML::Schema.new(response.body) xml = Nokogiri::XML(nodes.to_xml) xsd.valid?(xml) end |