Module | Sequel::Plugins::XmlSerializer::ClassMethods |
In: |
lib/sequel/plugins/xml_serializer.rb
|
CAMELIZE | = | proc{|s| s.camelize} | Proc that camelizes the input string, used for the :camelize option | |
DASHERIZE | = | proc{|s| s.dasherize} | 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 | = | proc{|s| s.underscore} | 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 130 130: def array_from_xml(xml, opts=OPTS) 131: node = Nokogiri::XML(xml).children.first 132: unless node 133: raise Error, "Malformed XML used" 134: end 135: node.children.reject{|c| c.is_a?(Nokogiri::XML::Text)}.map{|c| from_xml_node(c, opts)} 136: end
Return an instance of this class based on the provided XML.
# File lib/sequel/plugins/xml_serializer.rb, line 140 140: def from_xml(xml, opts=OPTS) 141: from_xml_node(Nokogiri::XML(xml).children.first, opts) 142: end
Return an instance of this class based on the given XML node, which should be Nokogiri::XML::Node instance. This should probably not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 147 147: def from_xml_node(parent, opts=OPTS) 148: new.from_xml_node(parent, opts) 149: end
Return an appropriate Nokogiri::XML::Builder instance used to create the XML. This should probably not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 154 154: def xml_builder(opts=OPTS) 155: if opts[:builder] 156: opts[:builder] 157: else 158: builder_opts = if opts[:builder_opts] 159: opts[:builder_opts] 160: else 161: {} 162: end 163: builder_opts[:encoding] = opts[:encoding] if opts.has_key?(:encoding) 164: Nokogiri::XML::Builder.new(builder_opts) 165: end 166: end
Return a proc (or any other object that responds to []), used for formatting XML tag names when serializing to XML. This should probably not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 171 171: def xml_deserialize_name_proc(opts=OPTS) 172: if opts[:name_proc] 173: opts[:name_proc] 174: elsif opts[:underscore] 175: UNDERSCORE 176: else 177: IDENTITY 178: end 179: end
Return a proc (or any other object that responds to []), used for formatting XML tag names when serializing to XML. This should probably not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 184 184: def xml_serialize_name_proc(opts=OPTS) 185: pr = if opts[:name_proc] 186: opts[:name_proc] 187: elsif opts[:dasherize] 188: DASHERIZE 189: elsif opts[:camelize] 190: CAMELIZE 191: else 192: IDENTITY 193: end 194: proc{|s| "#{pr[s]}_"} 195: end