Class: ActiveFedora::NomDatastream
Instance Attribute Summary
Attributes inherited from Datastream
#digital_object, #last_modified
Class Method Summary
collapse
Instance Method Summary
collapse
#autocreate?, #content=, #content_changed?, #datastream_content, #local_or_remote_content, #ng_xml, #ng_xml=, #ng_xml_changed?, #ng_xml_doesnt_change!, #ng_xml_will_change!, #to_xml, #xml_loaded
Methods inherited from Datastream
#create, #freeze, #frozen?, #initialize, #inspect, #label, #metadata?, #profile_from_hash, #realLabel, #save, #solrize_profile, #to_param
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/active_fedora/nom_datastream.rb', line 64
def method_missing method, *args, &block
if ng_xml.respond_to? method
ng_xml.send(method, *args, &block)
else
super
end
end
|
Class Method Details
.decorate_ng_xml(xml) ⇒ Object
35
36
37
38
39
|
# File 'lib/active_fedora/nom_datastream.rb', line 35
def self.decorate_ng_xml(xml)
xml.set_terminology terminology_options, &terminology
xml.nom!
xml
end
|
.default_attributes ⇒ Object
21
22
23
|
# File 'lib/active_fedora/nom_datastream.rb', line 21
def self.default_attributes
super.merge(:controlGroup => 'M', :mimeType => 'text/xml')
end
|
.from_xml(xml, tmpl = nil) ⇒ Object
Create an instance of this class based on xml content Careful! If you call this from a constructor, be sure to provide something ‘ie. self’ as the @tmpl. Otherwise, you will get an infinite loop!
29
30
31
32
33
|
# File 'lib/active_fedora/nom_datastream.rb', line 29
def self.from_xml(xml, tmpl=nil)
ds = self.new nil, nil
ds.content = xml.to_s
ds
end
|
.set_terminology(options = {}, &block) ⇒ Object
8
9
10
11
|
# File 'lib/active_fedora/nom_datastream.rb', line 8
def self.set_terminology(options = {}, &block)
@terminology_options = options || {}
@terminology = block
end
|
.terminology ⇒ Object
17
18
19
|
# File 'lib/active_fedora/nom_datastream.rb', line 17
def self.terminology
@terminology
end
|
.terminology_options ⇒ Object
13
14
15
|
# File 'lib/active_fedora/nom_datastream.rb', line 13
def self.terminology_options
@terminology_options
end
|
Instance Method Details
#respond_to?(*args) ⇒ Boolean
72
73
74
|
# File 'lib/active_fedora/nom_datastream.rb', line 72
def respond_to? *args
super || self.class.terminology.respond_to?(*args)
end
|
#serialize! ⇒ Object
41
42
43
|
# File 'lib/active_fedora/nom_datastream.rb', line 41
def serialize!
self.content = @ng_xml.to_s if @ng_xml
end
|
#to_solr ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/active_fedora/nom_datastream.rb', line 45
def to_solr
solr_doc = {}
ng_xml.terminology.flatten.select { |x| x.options[:index] }.each do |term|
term.values.each do |v|
Array(term.options[:index]).each do |index_as|
solr_doc[index_as] ||= []
if v.is_a? Nokogiri::XML::Node
solr_doc[index_as] << v.text
else
solr_doc[index_as] << v
end
end
end
end
solr_doc
end
|