module Sequel::Plugins::XmlSerializer::ClassMethods

  1. lib/sequel/plugins/xml_serializer.rb

Constants

CAMELIZE = :camelize.to_proc  

Proc that camelizes the input string, used for the :camelize option

DASHERIZE = :dasherize.to_proc  

Proc that dasherizes the input string, used for the :dasherize option

IDENTITY = proc{|s| s}  

Proc that returns the input string as is, used if no :name_proc, :dasherize, or :camelize option is used.

UNDERSCORE = :underscore.to_proc  

Proc that underscores the input string, used for the :underscore option

Public Instance methods

array_from_xml(xml, opts=OPTS)

Return an array of instances of this class based on the provided XML.

[show source]
    # File lib/sequel/plugins/xml_serializer.rb
134 def array_from_xml(xml, opts=OPTS)
135   node = Nokogiri::XML(xml).children.first
136   unless node 
137     raise Error, "Malformed XML used"
138   end
139   node.children.reject{|c| c.is_a?(Nokogiri::XML::Text)}.map{|c| from_xml_node(c, opts)}
140 end
from_xml(xml, opts=OPTS)

Return an instance of this class based on the provided XML.

[show source]
    # File lib/sequel/plugins/xml_serializer.rb
143 def from_xml(xml, opts=OPTS)
144   from_xml_node(Nokogiri::XML(xml).children.first, opts)
145 end
from_xml_node(parent, opts=OPTS)

Return an instance of this class based on the given XML node, which should be Nokogiri::XML::Node instance. This should not be used directly by user code.

[show source]
    # File lib/sequel/plugins/xml_serializer.rb
150 def from_xml_node(parent, opts=OPTS)
151   new.from_xml_node(parent, opts)
152 end
xml_builder(opts=OPTS)

Return an appropriate Nokogiri::XML::Builder instance used to create the XML. This should not be used directly by user code.

[show source]
    # File lib/sequel/plugins/xml_serializer.rb
157 def xml_builder(opts=OPTS)
158   if opts[:builder]
159     opts[:builder]
160   else
161     builder_opts = if opts[:builder_opts]
162       Hash[opts[:builder_opts]]
163     else
164       {}
165     end
166     builder_opts[:encoding] = opts[:encoding] if opts.has_key?(:encoding)
167     Nokogiri::XML::Builder.new(builder_opts)
168   end
169 end
xml_deserialize_name_proc(opts=OPTS)

Return a proc (or any other object that responds to []), used for formatting XML tag names when serializing to XML. This should not be used directly by user code.

[show source]
    # File lib/sequel/plugins/xml_serializer.rb
174 def xml_deserialize_name_proc(opts=OPTS)
175   if opts[:name_proc]
176     opts[:name_proc]
177   elsif opts[:underscore]
178     UNDERSCORE
179   else
180     IDENTITY
181   end
182 end
xml_serialize_name_proc(opts=OPTS)

Return a proc (or any other object that responds to []), used for formatting XML tag names when serializing to XML. This should not be used directly by user code.

[show source]
    # File lib/sequel/plugins/xml_serializer.rb
187 def xml_serialize_name_proc(opts=OPTS)
188   pr = if opts[:name_proc]
189     opts[:name_proc]
190   elsif opts[:dasherize]
191     DASHERIZE
192   elsif opts[:camelize]
193     CAMELIZE
194   else
195     IDENTITY
196   end
197   proc{|s| "#{pr[s]}_"}
198 end