Module: Peanuts::InstanceMethods
- Defined in:
- lib/peanuts/nuts.rb
Overview
See also ClassMethods
Instance Method Summary collapse
Instance Method Details
#parse(source, options = {}) ⇒ Object
210 211 212 |
# File 'lib/peanuts/nuts.rb', line 210 def parse(source, = {}) backend.parse(source, ) {|node| parse_node(node) } end |
#save(writer) ⇒ Object
214 215 216 |
# File 'lib/peanuts/nuts.rb', line 214 def save(writer) self.class.save(self, writer) end |
#save_to(*args) ⇒ Object
build() -> root element or string
build([options]) -> root element or string
build(destination[, options]) -> destination
Defines attribute mapping.
Arguments
destination-
Can be given a symbol a backend-specific object, an instance of String or IO classes.
:string-
will return an XML string.
:document-
will return a backend specific document object.
:object-
will return a backend specific object. New document will be created.
- an instance of
String -
the contents of the string will be replaced with the generated XML.
- an instance of
IO -
the IO will be written to.
options-
Backend-specific options
Example:
cat = Cat.new
cat.name = 'Pussy'
puts cat.save_to(:string)
...
doc = LibXML::XML::Document.new
cat.save_to(doc)
puts doc.to_s
242 243 244 245 246 |
# File 'lib/peanuts/nuts.rb', line 242 def save_to(*args) self.class._source_or_dest(*args) do |dest_type, dest, | save(XML::Writer.new(dest, dest_type, )) end end |