class Representable::XML::Binding
Public Class Methods
build_for(definition, *args)
click to toggle source
# File lib/representable/xml/binding.rb, line 7 def self.build_for(definition, *args) return Collection.new(definition, *args) if definition.array? return Hash.new(definition, *args) if definition.hash? and not definition[:use_attributes] # FIXME: hate this. return AttributeHash.new(definition, *args) if definition.hash? and definition[:use_attributes] return Attribute.new(definition, *args) if definition[:attribute] return Content.new(definition, *args) if definition[:content] new(definition, *args) end
Public Instance Methods
deserialize_from(nodes)
click to toggle source
# File lib/representable/xml/binding.rb, line 46 def deserialize_from(nodes) content_for(nodes.first) end
deserialize_method()
click to toggle source
# File lib/representable/xml/binding.rb, line 55 def deserialize_method :from_node end
read(node)
click to toggle source
# File lib/representable/xml/binding.rb, line 26 def read(node) nodes = find_nodes(node) return FragmentNotFound if nodes.size == 0 # TODO: write dedicated test! deserialize_from(nodes) end
serialize_for(value, parent)
click to toggle source
Creates wrapped node for the property.
# File lib/representable/xml/binding.rb, line 34 def serialize_for(value, parent) node = node_for(parent, as) serialize_node(node, value) end
serialize_method()
click to toggle source
DISCUSS: why is this public?
# File lib/representable/xml/binding.rb, line 51 def serialize_method :to_node end
serialize_node(node, value)
click to toggle source
# File lib/representable/xml/binding.rb, line 39 def serialize_node(node, value) return value if typed? node.content = value node end
write(parent, fragments)
click to toggle source
# File lib/representable/xml/binding.rb, line 16 def write(parent, fragments) wrap_node = parent if wrap = self[:wrap] parent << wrap_node = node_for(parent, wrap) end wrap_node << serialize_for(fragments, parent) end
Private Instance Methods
content_for(node)
click to toggle source
# File lib/representable/xml/binding.rb, line 74 def content_for(node) # TODO: move this into a ScalarDecorator. return node if typed? node.content end
find_nodes(doc)
click to toggle source
# File lib/representable/xml/binding.rb, line 64 def find_nodes(doc) selector = xpath selector = "#{self[:wrap]}/#{xpath}" if self[:wrap] nodes = doc.xpath(selector) end
node_for(parent, name)
click to toggle source
# File lib/representable/xml/binding.rb, line 70 def node_for(parent, name) Nokogiri::XML::Node.new(name.to_s, parent.document) end
xpath()
click to toggle source
# File lib/representable/xml/binding.rb, line 60 def xpath as end