Class: Cul::Hydra::Datastreams::StructMetadata
- Inherits:
-
ActiveFedora::Datastream
- Object
- ActiveFedora::Datastream
- Cul::Hydra::Datastreams::StructMetadata
show all
- Includes:
- ActiveFedora::Datastreams::NokogiriDatastreams
- Defined in:
- app/models/cul/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.
19
20
21
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 19
def initialize(digital_object=nil, dsid=nil, options={})
super
end
|
Class Method Details
.default_attributes ⇒ Object
7
8
9
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 7
def self.default_attributes
super.merge(:controlGroup => 'M', :mimeType => 'text/xml')
end
|
.div_template(prefix = "mets") ⇒ Object
15
16
17
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 15
def self.div_template(prefix="mets")
prefix.nil? ? '<div/>' : "<#{prefix}:div/>"
end
|
.xml_template ⇒ Object
11
12
13
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 11
def self.xml_template
Nokogiri::XML::Document.parse("<mets:structMap xmlns:mets=\"http://www.loc.gov/METS/\">")
end
|
Instance Method Details
#autocreate? ⇒ Boolean
29
30
31
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 29
def autocreate?
changed_attributes.has_key? :profile
end
|
#create_div_node(parent = nil, atts = {}) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 65
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
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 77
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_div ⇒ Object
90
91
92
93
94
95
96
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 90
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
|
#label ⇒ Object
38
39
40
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 38
def label
struct_map["LABEL"]
end
|
#label=(value) ⇒ Object
33
34
35
36
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 33
def label=(value)
struct_map["LABEL"] = value
ng_xml_will_change!
end
|
Indicates that this datastream has metadata content.
25
26
27
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 25
def metadata?
true
end
|
#prefix ⇒ Object
51
52
53
54
55
56
57
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 51
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
|
#proxies ⇒ Object
127
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
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 127
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
|
#recto ⇒ Object
114
115
116
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 114
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
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 100
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_map ⇒ Object
59
60
61
62
63
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 59
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
122
123
124
125
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 122
def to_solr(doc={})
doc[:structured_bsi] = (has_content? ? 'true' : 'false')
doc
end
|
#type ⇒ Object
47
48
49
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 47
def type
struct_map["TYPE"]
end
|
#type=(value) ⇒ Object
42
43
44
45
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 42
def type=(value)
struct_map["TYPE"] = value
ng_xml_will_change!
end
|
#verso ⇒ Object
118
119
120
|
# File 'app/models/cul/hydra/datastreams/struct_metadata.rb', line 118
def verso
divs_with_attribute(false, 'LABEL', 'Verso').first
end
|