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

#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

#rectoObject



107
108
109
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 107

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



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 93

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



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

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



111
112
113
# File 'app/models/cul/scv/hydra/datastreams/struct_metadata.rb', line 111

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