Module: Peanuts::MappableObject

Defined in:
lib/peanuts/mappable.rb

Overview

See also MappableType

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other) ⇒ Object

:nodoc:



10
11
12
# File 'lib/peanuts/mappable.rb', line 10

def self.included(other) #:nodoc:
  MappableType.init(other)
end

Instance Method Details

#from_xml(source, options = {}) ⇒ Object



14
15
16
17
18
# File 'lib/peanuts/mappable.rb', line 14

def from_xml(source, options = {})
  source = XML::Reader.new(source, options) unless source.is_a?(XML::Reader)
  e = source.find_element
  e && Mapper.of(self.class).read(self, source)
end

#to_xml(dest = :string, options = {}) ⇒ Object

save_to(:string|:document[, options]) -> new_string|new_document

save_to(string|iolike|document[, options]) -> string|iolike|document

Defines attribute mapping.

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


35
36
37
38
39
# File 'lib/peanuts/mappable.rb', line 35

def to_xml(dest = :string, options = {})
  dest = XML::Writer.new(dest, options) unless dest.is_a?(XML::Writer)
  Mapper.of(self.class).write(self, dest)
  dest.result
end