Module: AwesomeXML::Type

Defined in:
lib/awesome_xml/type.rb

Defined Under Namespace

Classes: UnknownNodeType

Constant Summary collapse

NATIVE_TYPE_CLASSES =
{
  text: AwesomeXML::Text,
  integer: AwesomeXML::Integer,
  float: AwesomeXML::Float,
  duration: AwesomeXML::Duration,
  date_time: AwesomeXML::DateTime
}.freeze

Class Method Summary collapse

Class Method Details

.for(type, class_name) ⇒ Object

Takes a type (Symbol, String or Class) passed in from a ‘.node` method call and the name of the class it was called in. The latter is needed to correctly assign the namespace if the type is given in String form. Returns a class, either one of the native `AwesomeXML` types or a user-defined class. Raises an exception if `type` is given as a Symbol, but does not represent one of the native types.



20
21
22
23
24
25
26
27
28
29
# File 'lib/awesome_xml/type.rb', line 20

def self.for(type, class_name)
  case type
  when Symbol
    NATIVE_TYPE_CLASSES[type] || fail(UnknownNodeType.new(type))
  when String
    [class_name, type].join('::').constantize
  when Class
    type
  end
end