Module: Representable::XML

Included in:
AttributeHash, Collection, Hash
Defined in:
lib/representable/xml.rb,
lib/representable/xml/hash.rb,
lib/representable/xml/binding.rb,
lib/representable/xml/collection.rb

Defined Under Namespace

Modules: AttributeHash, ClassMethods, Collection, Hash Classes: Binding

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


8
9
10
11
12
13
14
15
# File 'lib/representable/xml.rb', line 8

def self.included(base)
  base.class_eval do
    include Representable
    extend ClassMethods
    self.representation_wrap = true # let representable compute it.
    register_feature Representable::XML
  end
end

Instance Method Details

#from_node(node, options = {}) ⇒ Object


34
35
36
# File 'lib/representable/xml.rb', line 34

def from_node(node, options={})
  update_properties_from(node, options, Binding)
end

#from_xml(doc, *args) ⇒ Object


28
29
30
31
32
# File 'lib/representable/xml.rb', line 28

def from_xml(doc, *args)
  node = parse_xml(doc, *args)

  from_node(node, *args)
end

#to_node(options = {}) ⇒ Object

Returns a Nokogiri::XML object representing this object.


39
40
41
42
43
44
# File 'lib/representable/xml.rb', line 39

def to_node(options={})
  options[:doc] ||= Nokogiri::XML::Document.new
  root_tag = options[:wrap] || representation_wrap(options)

  create_representation_with(Nokogiri::XML::Node.new(root_tag.to_s, options[:doc]), options, Binding)
end

#to_xml(*args) ⇒ Object


46
47
48
# File 'lib/representable/xml.rb', line 46

def to_xml(*args)
  to_node(*args).to_s
end