lib/happymapper/anonymous_mapper.rb
#
# Define a HappyMapper element on the provided class based on
# the node provided.
#
Define a HappyMapper element on the provided class based on
the node provided.
Define a HappyMapper element on the provided class based on the node provided .
def define_element_on_class(klass, node)
      if node.text?
        klass.content :content, String if node.content.strip != ''
        return
      end
      element_type = if node.elements.any? || node.attributes.any?
                       create_happymapper_class_from_node(node)
                     else
                       String
                     end
      element_name = underscore(node.name)
      method = klass.elements.find { |e| e.name == element_name } ? :has_many : :has_one
      options = {}
      options[:tag] = node.name
      namespace = node.namespace
      options[:namespace] = namespace.prefix if namespace
      options[:xpath] = './' unless element_type == String
      klass.send(method, element_name, element_type, options)
    end
def define_element_on_class ( klass , node ) if node . text? klass . content :content , String if node . content . strip != '' return end element_type = if node . elements . any? || node . attributes . any? create_happymapper_class_from_node ( node ) else String end element_name = underscore ( node . name ) method = klass . elements . find { | e | e . name == element_name } ? :has_many : :has_one options = { } options [ :tag ] = node . name namespace = node . namespace options [ :namespace ] = namespace . prefix if namespace options [ :xpath ] = './' unless element_type == String klass . send ( method , element_name , element_type , options ) end
Define a HappyMapper element on the provided class based on
the node provided.
Define a HappyMapper element on the provided class based on the node provided .
# When a text node has been provided create the necessary # HappyMapper content attribute if the text happens to contain # some content. # When the node has child elements, that are not text # nodes, then we want to recursively define a new HappyMapper # class that will have elements and attributes.
klass
<not_specific>
node
<not_specific>