Module: DataMapper::Serialize::XMLSerializers::Nokogiri

Defined in:
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/xml_serializers/nokogiri.rb

Class Method Summary collapse

Class Method Details

.add_node(parent, name, value, attrs = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/gems/dm-serializer-0.9.9/lib/dm-serializer/xml_serializers/nokogiri.rb', line 18

def self.add_node(parent, name, value, attrs = {})
  node = ::Nokogiri::XML::Node.new(name, parent.document)
  node << ::Nokogiri::XML::Text.new(value.to_s, parent.document) unless value.nil?
  attrs.each {|attr_name, attr_val| node[attr_name] = attr_val }
  parent << node
  node
end

.new_documentObject



5
6
7
# File 'lib/gems/dm-serializer-0.9.9/lib/dm-serializer/xml_serializers/nokogiri.rb', line 5

def self.new_document
  ::Nokogiri::XML::Document.new
end

.root_node(doc, name, attrs = {}) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/gems/dm-serializer-0.9.9/lib/dm-serializer/xml_serializers/nokogiri.rb', line 9

def self.root_node(doc, name, attrs = {})
  root = ::Nokogiri::XML::Node.new(name, doc)
  attrs.each do |attr_name, attr_val|
    root[attr_name] = attr_val
  end
  doc.root.nil? ? doc.root = root : doc.root << root
  root
end