class Matterhorn::DublinCore
<?xml version=“1.0”?> <dublincore xmlns=“www.opencastproject.org/xsd/1.0/dublincore/” xmlns:xsi=“www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation="http://www.opencastproject.org http://www.opencastproject.org/schema.xsd" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oc="http://www.opencastproject.org/matterhorn/"> <dcterms:title xml:lang="en"> Land and Vegetation: Key players on the Climate Scene </dcterms:title> <dcterms:subject> climate, land, vegetation </dcterms:subject> <dcterms:description xml:lang="en"> Introduction lecture from the Institute for Atmospheric and Climate Science. </dcterms:description> <dcterms:publisher> ETH Zurich, Switzerland </dcterms:publisher> <dcterms:identifier> 10.0000/5819 </dcterms:identifier> <dcterms:modified xsi:type="dcterms:W3CDTF"> 2007-12-05 </dcterms:modified> <dcterms:format xsi:type="dcterms:IMT"> video/x-dv </dcterms:format> <oc:promoted> true </oc:promoted>
</dublincore>
Constants
- NS
————————————————————————– const definitions —
Public Class Methods
new(xml = nil)
click to toggle source
—————————————————————————– initialization —
# File lib/matterhorn/dublin_core.rb, line 55 def initialize(xml = nil) if !xml.nil? @document = Nokogiri::XML(xml) else @document = Nokogiri::XML::Builder.new do |xml| xml.dublincore(NS) do end end .doc end end
Public Instance Methods
add_value(ns, key, value)
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 162 def add_value(ns, key, value) sibling = @document.xpath("/xmlns:dublincore/#{ns}:#{key}").last elem = Nokogiri::XML::Element.new(key, @document) elem.content = value.to_s.strip elem.namespace = get_ns(ns) unless ns.nil? if !sibling.nil? sibling.after(elem) else @document.root << elem end elem.content end
document()
click to toggle source
———————————————————————————– methodes —
# File lib/matterhorn/dublin_core.rb, line 70 def document @document end
each_dcterms_element(&block)
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 75 def each_dcterms_element(&block) each_element('dcterms', &block) end
each_element(ns) { |name, content.strip| ... }
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 176 def each_element(ns, &block) @document.xpath("/xmlns:dublincore/#{ns}:*").each do |elem| yield elem.name, elem.content.to_s.strip end end
get_ns(ns)
click to toggle source
———————————————————————————— helpers —
# File lib/matterhorn/dublin_core.rb, line 137 def get_ns(ns) @document.root.namespace_definitions.find { |n| n.prefix == ns } end
get_value(ns, key)
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 142 def get_value(ns, key) elem = @document.xpath("/xmlns:dublincore/#{ns}:#{key}").first return nil if elem.nil? elem.content.to_s.strip end
inspect()
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 92 def inspect to_xml.to_s end
method_missing(method, *args, &block)
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 97 def method_missing(method, *args, &block) # analyse mehtod splitted_method = method.to_s.split('_') if splitted_method.first == 'add' method_name = :add_value splitted_method.shift elsif splitted_method.first == 'list' method_name = :list_value splitted_method.shift elsif splitted_method.last.end_with?('=') method_name = :set_value splitted_method.last.chop! else method_name = :get_value end # namespace, key and value namespace = if !get_ns(splitted_method.first).nil? splitted_method.shift else 'xmlns' end key = splitted_method.join('_') value = args[0] MatterhornWhymper.logger.debug { "#{self.class.name}#method_missing | " + "method: #{method_name.to_s}; namespace: #{namespace}; " + "key: #{key}; value: #{value.to_s}" } # call method params = case method_name when :get_value then [namespace, key] when :set_value then [namespace, key, args[0].to_s] when :add_value then [namespace, key, args[0].to_s] end send(method_name, *params) end
save(file)
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 80 def save(file) File.open(file, 'w') do |file| file.write(@document.to_xml) end end
set_value(ns, key, value)
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 149 def set_value(ns, key, value) if !(elem = @document.at_xpath("/xmlns:dublincore/#{ns}:#{key}")).nil? elem.content = value.to_s.strip else elem = Nokogiri::XML::Element.new(key, @document) elem.content = value.to_s.strip elem.namespace = get_ns(ns) unless ns.nil? @document.root << elem end elem.content end
to_xml()
click to toggle source
# File lib/matterhorn/dublin_core.rb, line 87 def to_xml @document.to_xml end