module Sequel::Plugins::XmlSerializer::ClassMethods

def array_from_xml(xml, opts=OPTS)

the provided XML.
Return an array of instances of this class based on
def array_from_xml(xml, opts=OPTS)
  node = Nokogiri::XML(xml).children.first
  unless node 
    raise Error, "Malformed XML used"
  end
  node.children.reject{|c| c.is_a?(Nokogiri::XML::Text)}.map{|c| from_xml_node(c, opts)}
end

def from_xml(xml, opts=OPTS)

Return an instance of this class based on the provided XML.
def from_xml(xml, opts=OPTS)
  from_xml_node(Nokogiri::XML(xml).children.first, opts)
end

def from_xml_node(parent, opts=OPTS)

This should not be used directly by user code.
XML node, which should be Nokogiri::XML::Node instance.
Return an instance of this class based on the given
def from_xml_node(parent, opts=OPTS)
  new.from_xml_node(parent, opts)
end

def xml_builder(opts=OPTS)

directly by user code.
used to create the XML. This should not be used
Return an appropriate Nokogiri::XML::Builder instance
def xml_builder(opts=OPTS)
  if opts[:builder]
    opts[:builder]
  else
    builder_opts = if opts[:builder_opts]
      Hash[opts[:builder_opts]]
    else
      {}
    end
    builder_opts[:encoding] = opts[:encoding] if opts.has_key?(:encoding)
    Nokogiri::XML::Builder.new(builder_opts)
  end
end

def xml_deserialize_name_proc(opts=OPTS)

This should not be used directly by user code.
used for formatting XML tag names when serializing to XML.
Return a proc (or any other object that responds to []),
def xml_deserialize_name_proc(opts=OPTS)
  if opts[:name_proc]
    opts[:name_proc]
  elsif opts[:underscore]
    UNDERSCORE
  else
    IDENTITY
  end
end

def xml_serialize_name_proc(opts=OPTS)

This should not be used directly by user code.
used for formatting XML tag names when serializing to XML.
Return a proc (or any other object that responds to []),
def xml_serialize_name_proc(opts=OPTS)
  pr = if opts[:name_proc]
    opts[:name_proc]
  elsif opts[:dasherize]
    DASHERIZE
  elsif opts[:camelize]
    CAMELIZE
  else
    IDENTITY
  end
  proc{|s| "#{pr[s]}_"}
end