Module: ActiveFedora::Datastreams::NokogiriDatastreams::ClassMethods

Defined in:
lib/active_fedora/datastreams/nokogiri_datastreams.rb

Instance Method Summary collapse

Instance Method Details

#decorate_ng_xml(xml) ⇒ Object



32
33
34
# File 'lib/active_fedora/datastreams/nokogiri_datastreams.rb', line 32

def decorate_ng_xml(xml)
  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!

Parameters:

  • xml (String, File, Nokogiri::XML::Node)

    the xml content to build from

  • tmpl (ActiveFedora::OmDatastream) (defaults to: nil)

    the Datastream object that you are building @default a new instance of this class



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_fedora/datastreams/nokogiri_datastreams.rb', line 12

def from_xml(xml, tmpl=nil)
  tmpl = self.new if tmpl.nil?  ## This path is used only for unit testing (e.g. MarpaDCDatastream.from_xml(fixture("data.xml")) )

  if !xml.present?
    tmpl.ng_xml = self.xml_template
  elsif xml.kind_of? Nokogiri::XML::Node || xml.kind_of?(Nokogiri::XML::Document)
    tmpl.ng_xml = xml
  else
    tmpl.ng_xml = Nokogiri::XML::Document.parse(xml)
  end

  tmpl.ng_xml_doesnt_change!

  return tmpl
end

#xml_templateObject



28
29
30
# File 'lib/active_fedora/datastreams/nokogiri_datastreams.rb', line 28

def xml_template
  Nokogiri::XML::Document.parse("<xml/>")
end