Module | Sequel::Plugins::XmlSerializer::ClassMethods |
In: |
lib/sequel/plugins/xml_serializer.rb
|
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 |
Return an array of instances of this class based on the provided XML.
# File lib/sequel/plugins/xml_serializer.rb, line 132 132: def array_from_xml(xml, opts=OPTS) 133: node = Nokogiri::XML(xml).children.first 134: unless node 135: raise Error, "Malformed XML used" 136: end 137: node.children.reject{|c| c.is_a?(Nokogiri::XML::Text)}.map{|c| from_xml_node(c, opts)} 138: end
Return an instance of this class based on the provided XML.
# File lib/sequel/plugins/xml_serializer.rb, line 141 141: def from_xml(xml, opts=OPTS) 142: from_xml_node(Nokogiri::XML(xml).children.first, opts) 143: end
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.
# File lib/sequel/plugins/xml_serializer.rb, line 148 148: def from_xml_node(parent, opts=OPTS) 149: new.from_xml_node(parent, opts) 150: end
Return an appropriate Nokogiri::XML::Builder instance used to create the XML. This should not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 155 155: def xml_builder(opts=OPTS) 156: if opts[:builder] 157: opts[:builder] 158: else 159: builder_opts = if opts[:builder_opts] 160: Hash[opts[:builder_opts]] 161: else 162: {} 163: end 164: builder_opts[:encoding] = opts[:encoding] if opts.has_key?(:encoding) 165: Nokogiri::XML::Builder.new(builder_opts) 166: end 167: end
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.
# File lib/sequel/plugins/xml_serializer.rb, line 172 172: def xml_deserialize_name_proc(opts=OPTS) 173: if opts[:name_proc] 174: opts[:name_proc] 175: elsif opts[:underscore] 176: UNDERSCORE 177: else 178: IDENTITY 179: end 180: end
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.
# File lib/sequel/plugins/xml_serializer.rb, line 185 185: def xml_serialize_name_proc(opts=OPTS) 186: pr = if opts[:name_proc] 187: opts[:name_proc] 188: elsif opts[:dasherize] 189: DASHERIZE 190: elsif opts[:camelize] 191: CAMELIZE 192: else 193: IDENTITY 194: end 195: proc{|s| "#{pr[s]}_"} 196: end