module Representable::XML
Public Class Methods
included(base)
click to toggle source
# File lib/representable/xml.rb, line 13 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
Public Instance Methods
from_node(node, options={})
click to toggle source
# File lib/representable/xml.rb, line 39 def from_node(node, options={}) update_properties_from(node, options, Binding) end
from_xml(doc, *args)
click to toggle source
# File lib/representable/xml.rb, line 33 def from_xml(doc, *args) node = parse_xml(doc, *args) from_node(node, *args) end
to_node(options={})
click to toggle source
Returns a Nokogiri::XML object representing this object.
# File lib/representable/xml.rb, line 44 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)
click to toggle source
# File lib/representable/xml.rb, line 51 def to_xml(*args) to_node(*args).to_s end
Private Instance Methods
parse_xml(doc, *args)
click to toggle source
# File lib/representable/xml.rb, line 61 def parse_xml(doc, *args) node = Nokogiri::XML(doc) node.remove_namespaces! if remove_namespaces? node.root end
remove_namespaces?()
click to toggle source
# File lib/representable/xml.rb, line 56 def remove_namespaces? # TODO: make local Config easily extendable so you get Config#remove_ns? etc. representable_attrs.options[:remove_namespaces] end