Module | Sequel::Plugins::XmlSerializer::ClassMethods |
In: |
lib/sequel/plugins/xml_serializer.rb
|
CAMELIZE | = | proc(&:camelize) | Proc that camelizes the input string, used for the :camelize option | |
DASHERIZE | = | proc(&: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(&: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 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 142 142: def from_xml(xml, opts=OPTS) 143: from_xml_node(Nokogiri::XML(xml).children.first, opts) 144: 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 149 149: def from_xml_node(parent, opts=OPTS) 150: new.from_xml_node(parent, opts) 151: 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 156 156: def xml_builder(opts=OPTS) 157: if opts[:builder] 158: opts[:builder] 159: else 160: builder_opts = if opts[:builder_opts] 161: opts[:builder_opts] 162: else 163: {} 164: end 165: builder_opts[:encoding] = opts[:encoding] if opts.has_key?(:encoding) 166: Nokogiri::XML::Builder.new(builder_opts) 167: end 168: 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 173 173: def xml_deserialize_name_proc(opts=OPTS) 174: if opts[:name_proc] 175: opts[:name_proc] 176: elsif opts[:underscore] 177: UNDERSCORE 178: else 179: IDENTITY 180: end 181: 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 186 186: def xml_serialize_name_proc(opts=OPTS) 187: pr = if opts[:name_proc] 188: opts[:name_proc] 189: elsif opts[:dasherize] 190: DASHERIZE 191: elsif opts[:camelize] 192: CAMELIZE 193: else 194: IDENTITY 195: end 196: proc{|s| "#{pr[s]}_"} 197: end