Class: UWDC::Mods

Inherits:
Mets
  • Object
show all
Defined in:
lib/uwdc/mods.rb

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

#id, #xml

Class Method Summary collapse

Instance Method Summary collapse

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

.attributesObject

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

#abstractsObject

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_conditionsObject

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

#datesObject

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

#formsObject

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

#metadataObject

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

#namesObject

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

#nodesObject

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

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 related_items
  nodes.xpath("//mods/relatedItem").inject([]){|arr,node| arr << capture_relation(node) ; arr }
end

#subjectsObject

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_geographicObject

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

#titlesObject

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

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