Class: UWDC::Mets

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

Overview

Public: Methods to obtain UWDC METS metadata via an object identifier.

Examples

UWDC::Mets.new(‘ECJ6ZXEYWUE7B8W’) # => object fetched from Fedora

UWDC::Mets.new(‘ECJ6ZXEYWUE7B8W’, File.read(‘../file.xml’)) # => object constructed from XML file

Direct Known Subclasses

DublinCore, FileSec, Mods, Origin, RelsExt, StructMap

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, xml = nil) ⇒ Mets

Public: Intialize a UWDC Mets object

id - A UWDC identifier. xml - An optional XML file.

Raises XmlNotFound if the xml file cannot be found or fetched.

Raises:



20
21
22
23
24
# File 'lib/uwdc/mets.rb', line 20

def initialize(id, xml=nil)
  @id = id
  @xml ||= UWDC::XML.new(@id,xml)
  raise(XmlNotFound) unless [nil,200].include?(@xml.status)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/uwdc/mets.rb', line 12

def id
  @id
end

#xmlObject

Returns the value of attribute xml.



12
13
14
# File 'lib/uwdc/mets.rb', line 12

def xml
  @xml
end

Instance Method Details

#display(id = @id) ⇒ Object

Public: Access the Display class/methods for the METS file

Example

# => UWDC::Display

Returns a UWDC::Display object



154
155
156
# File 'lib/uwdc/mets.rb', line 154

def display(id=@id)
  @display = Display.new(id)
end

#dublin_core(id = @id) ⇒ Object

Public: Access the DublinCore descriptive metadata XML nodes

Example

# => UWDC::DublinCore

Returns a UWDC::DublinCore object



142
143
144
# File 'lib/uwdc/mets.rb', line 142

def dublin_core(id=@id)
  @dublin_core = DublinCore.new(id)
end

#file_sec(id = @id) ⇒ Object

Public: Access the FileSec file section XML nodes

Example

# => UWDC::FileSec

Returns a UWDC::FileSec object



130
131
132
# File 'lib/uwdc/mets.rb', line 130

def file_sec(id=@id)
  @file_sec = FileSec.new(id)
end

#modsObject

Public: Access the MODS descriptive metadata XML nodes

Example

# => UWDC::Mods

Returns a UWDC::Mods object



82
83
84
# File 'lib/uwdc/mets.rb', line 82

def mods
  @mods = Mods.new(@id)
end

#nodesObject

Public: Access the XML nodes of the METS file

Example

# => Nokogiri::XML::NodeSet

Returns the Nokogiri::XML::NodeSet for the parsed METS file



34
35
36
# File 'lib/uwdc/mets.rb', line 34

def nodes
  @xml.nodes
end

#originObject

Public: Access the Origin metadata XML nodes

Example

# => UWDC::Origin

Returns a UWDC::Origin object



94
95
96
# File 'lib/uwdc/mets.rb', line 94

def origin
  @origin = Origin.new(@id)
end

#rels_ext(id = @id) ⇒ Object

Public: Access the RelsExt RDF relation XML nodes

Example

# => UWDC::RelsExt

Returns a UWDC::RelsExt object



118
119
120
# File 'lib/uwdc/mets.rb', line 118

def rels_ext(id=@id)
  @rels_ext = RelsExt.new(id)
end

#struct_map(id = @id) ⇒ Object

Public: Access the StructMap structural map section XML nodes

Example

# => UWDC::StructMap

Returns a UWDC::StructMap object



106
107
108
# File 'lib/uwdc/mets.rb', line 106

def struct_map(id=@id)
  @struct_map = StructMap.new(id)
end

#to_jsonObject

Public: Convert the XML nodes to JSON

Example

# => …

Returns the Nokogiri::XML::NodeSet as JSON



46
47
48
# File 'lib/uwdc/mets.rb', line 46

def to_json
  Hash.from_xml(nodes.to_xml).to_json
end

#to_rubyObject

Public: Convert the XML nodes to Ruby

Example

# => …

Returns the Nokogiri::XML::NodeSet as a Ruby Hash



58
59
60
# File 'lib/uwdc/mets.rb', line 58

def to_ruby
  Hash.from_xml(nodes.to_xml)
end

#to_xmlObject

Public: Convert the XML nodes to XML

Example

# => “<mets>…”

Returns the Nokogiri::XML::NodeSet as XML



70
71
72
# File 'lib/uwdc/mets.rb', line 70

def to_xml
  nodes.to_xml
end