Module: XMLable::Mixins::BareValue

Defined in:
lib/xmlable/mixins/bare_value.rb

Overview

BareValue contains logic to get the bare value.

All XML object such as Integer, Date, String, etc are wrapped with the
proxy classes. This module helps to unwrap the real value.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



9
10
11
12
13
14
# File 'lib/xmlable/mixins/bare_value.rb', line 9

def method_missing(name, *args, &block)
  return super unless name.to_s =~ /!$/
  return super unless key?(name)
  name = name.to_s.gsub(/!$/,'').to_sym
  __extract_bare_value(super)
end

Instance Method Details

#[](key) ⇒ XMLable::Mixins::Object, ...

Get object value

It unwraps the object value if object key ends with '!' symbol.

Returns:



22
23
24
25
# File 'lib/xmlable/mixins/bare_value.rb', line 22

def [](key)
  return super unless key.to_s =~ /!$/
  __extract_bare_value(super)
end

#__extract_bare_value(obj) ⇒ Object+

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Unwrap objects

Parameters:

Returns:



36
37
38
# File 'lib/xmlable/mixins/bare_value.rb', line 36

def __extract_bare_value(obj)
  obj.respond_to?(:map) ?  obj.map(&:__object) : obj.__object
end