Class: Cul::Scv::Hydra::Datastreams::StructMetadata

Inherits:
ActiveFedora::Datastream
  • Object
show all
Includes:
ActiveFedora::Datastreams::NokogiriDatastreams
Defined in:
app/models/cul/scv/hydra/datastreams/struct_metadata.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(digital_object = nil, dsid = nil, options = {}) ⇒ StructMetadata

Returns a new instance of StructMetadata.



20
21
22
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 20

def initialize(digital_object=nil, dsid=nil, options={})
  super
end

Class Method Details

.default_attributesObject



8
9
10
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 8

def self.default_attributes
  super.merge(:controlGroup => 'M', :mimeType => 'text/xml')
end

.div_template(prefix = "mets") ⇒ Object



16
17
18
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 16

def self.div_template(prefix="mets")
  prefix.nil? ? '<div/>' : "<#{prefix}:div/>"
end

.xml_templateObject



12
13
14
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 12

def self.xml_template
  Nokogiri::XML::Document.parse("<mets:structMap xmlns:mets=\"http://www.loc.gov/METS/\">")
end

Instance Method Details

#autocreate?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 30

def autocreate?
  changed_attributes.has_key? :profile
end

#create_div_node(parent = nil, atts = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 66

def create_div_node(parent=nil, atts={})
  if parent.nil?
    parent = struct_map
  end
  divNode = parent.add_child(StructMetadata.div_template(parent.namespace.prefix)).first
  [:label, :order, :contentids]. each do |key|
    divNode[key.to_s.upcase] = atts[key].to_s if atts.has_key? key
  end
  ng_xml_will_change! if (divNode.document == ng_xml.document)
  divNode
end

#divs_with_attribute(descend = true, name = nil, value = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 78

def divs_with_attribute(descend=true, name=nil, value=nil)
  prefix = self.prefix || 'xmlns'
  xpath = descend ? "//#{prefix}:div" : "/#{prefix}:structMap/#{prefix}:div"
  if !name.nil?
    xpath << "[@#{name}"
    if !value.nil?
      xpath << "='#{value}'"
    end
    xpath << ']'
  end
  ng_xml.xpath(xpath, ng_xml.namespaces)
end

#first_ordered_content_divObject



91
92
93
94
95
96
97
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 91

def first_ordered_content_div
  divs_with_contentids_attr = self.divs_with_attribute(true, 'CONTENTIDS')
  sorted_divs_with_contentids_attr = divs_with_contentids_attr.sort_by{ |node|
    node.attr("ORDER").to_i
  }
  return sorted_divs_with_contentids_attr.first
end

#labelObject



39
40
41
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 39

def label
  struct_map["LABEL"]
end

#label=(value) ⇒ Object



34
35
36
37
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 34

def label=(value)
  struct_map["LABEL"] = value
  ng_xml_will_change!
end

#metadata?Boolean

Indicates that this datastream has metadata content.

Returns:

  • (Boolean)

    true



26
27
28
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 26

def metadata?
  true
end

#prefixObject



52
53
54
55
56
57
58
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 52

def prefix
  prefix = nil
  ng_xml.namespaces.each do |p, href|
    prefix = p.sub(/xmlns:/,'') if href == "http://www.loc.gov/METS/"
  end
  prefix
end

#proxiesObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 128

def proxies
  divs = divs_with_attribute(true)
  graph_context_uri = RDF::URI("info:fedora/#{self.pid}")
  file_system = self.type.eql?(RDF::NFO[:"#Filesystem"].to_s)
  divs.collect do |div|
    proxy_uri_chain = proxy_uri_chain_for(div)
    proxy_resource_uri = proxy_uri_chain.pop
    if div['CONTENTIDS']
      subclass = file_system ?
        NFO::FileDataObject : SC::Canvas
      proxy = subclass.new(proxy_resource_uri, graph_context_uri)
      proxy.proxyFor = RDF::URI(div['CONTENTIDS'])
    else
      subclass = file_system ?
        NFO::Folder : SC::Sequence
      proxy = subclass.new(proxy_resource_uri, graph_context_uri)
    end
    if div.parent and div.parent.name == 'div'
      proxy.belongsToContainer = proxy_uri_for(div.parent)
    end
    proxy.isPartOf = proxy_uri_chain unless proxy_uri_chain.empty?
    proxy.index = div['ORDER']
    proxy.label = div['LABEL']
    proxy
  end
end

#rectoObject



115
116
117
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 115

def recto
  divs_with_attribute(false, 'LABEL', 'Recto').first
end

#recto_verso!Object

a convenience method for setting attributes and creating divs (if necessary) for R/V structure returns the mets:structMap node



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 101

def recto_verso!
  self.type= 'physical' unless self.type == 'physical'
  self.label= 'Sides' unless self.label == 'Sides'
  create_div_node struct_map, {:order=>'1'} unless divs_with_attribute(false,'ORDER','1').first
  create_div_node struct_map, {:order=>'2'} unless divs_with_attribute(false,'ORDER','2').first
  if (div = divs_with_attribute(false,'ORDER','1').first)
    div['LABEL'] = 'Recto' unless div['LABEL'] == 'Recto'
  end
  if (div = divs_with_attribute(false,'ORDER','2').first)
    div['LABEL'] = 'Verso' unless div['LABEL'] == 'Verso'
  end
  struct_map
end

#struct_mapObject



60
61
62
63
64
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 60

def struct_map
  prefix = self.prefix
  path = prefix.nil? ? 'xmlns:structMap' : "#{prefix}:structMap"
  ng_xml.xpath(path, ng_xml.namespaces).first
end

#to_solr(doc = {}) ⇒ Object



123
124
125
126
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 123

def to_solr(doc={})
  doc[:structured_bsi] = (has_content? ? 'true' : 'false')
  doc
end

#typeObject



48
49
50
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 48

def type
  struct_map["TYPE"]
end

#type=(value) ⇒ Object



43
44
45
46
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 43

def type=(value)
  struct_map["TYPE"] = value
  ng_xml_will_change!
end

#versoObject



119
120
121
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 119

def verso
  divs_with_attribute(false, 'LABEL', 'Verso').first
end