Module: Iora::Associations::Helpers

Included in:
HasAttribute, HasMany, HasOne
Defined in:
lib/iora/associations/helpers.rb

Overview

The Helpers modules defines utility functions for associations.

Instance Method Summary collapse

Instance Method Details

#parse_element(node, klass) ⇒ Object

Convert a Nokogiri::XML::Node to an Element or core object.

Parameters:

  • node (Nokogiri::XML::Node)

    the node object

  • klass (Class)

    the class

Returns:

  • (Object)

14
15
16
17
18
19
20
# File 'lib/iora/associations/helpers.rb', line 14

def parse_element(node, klass)
  case
  when node.nil? then nil
  when klass.superclass == Iora::Element then klass.new(node)
  else Coercer.coerce(node.text).to(klass)
  end
end

#tag_for(name) ⇒ String

Get the XML tag name that corresponds to a method name.

Parameters:

  • name (Symbol)

    the method name

Returns:

  • (String)

    the tag name


26
27
28
# File 'lib/iora/associations/helpers.rb', line 26

def tag_for(name)
  name.to_s.remove(/[^a-z]+/)
end