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 111 111: def array_from_xml(xml, opts={}) 112: Nokogiri::XML(xml).children.first.children.reject{|c| c.is_a?(Nokogiri::XML::Text)}.map{|c| from_xml_node(c, opts)} 113: end
Return an instance of this class based on the provided XML.
# File lib/sequel/plugins/xml_serializer.rb, line 117 117: def from_xml(xml, opts={}) 118: from_xml_node(Nokogiri::XML(xml).children.first, opts) 119: 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 124 124: def from_xml_node(parent, opts={}) 125: new.from_xml_node(parent, opts) 126: 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 136 136: def xml_builder(opts={}) 137: if opts[:builder] 138: opts[:builder] 139: else 140: builder_opts = if opts[:builder_opts] 141: opts[:builder_opts] 142: else 143: {} 144: end 145: builder_opts[:encoding] = opts[:encoding] if opts.has_key?(:encoding) 146: Nokogiri::XML::Builder.new(builder_opts) 147: end 148: 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 153 153: def xml_deserialize_name_proc(opts={}) 154: if opts[:name_proc] 155: opts[:name_proc] 156: elsif opts[:underscore] 157: UNDERSCORE 158: else 159: IDENTITY 160: end 161: 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 166 166: def xml_serialize_name_proc(opts={}) 167: pr = if opts[:name_proc] 168: opts[:name_proc] 169: elsif opts[:dasherize] 170: DASHERIZE 171: elsif opts[:camelize] 172: CAMELIZE 173: else 174: IDENTITY 175: end 176: proc{|s| "#{pr[s]}_"} 177: end