Class: Gloo::Convert::Converter
- Inherits:
-
Object
- Object
- Gloo::Convert::Converter
- Defined in:
- lib/gloo/convert/converter.rb
Instance Method Summary collapse
-
#convert(value, to_type, default = nil) ⇒ Object
Convert the given value to the specified type, or if no conversion is available, revert to default.
-
#initialize(engine) ⇒ Converter
constructor
Initializer.
Constructor Details
#initialize(engine) ⇒ Converter
Initializer.
14 15 16 |
# File 'lib/gloo/convert/converter.rb', line 14 def initialize( engine ) @engine = engine end |
Instance Method Details
#convert(value, to_type, default = nil) ⇒ Object
Convert the given value to the specified type, or if no conversion is available, revert to default.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gloo/convert/converter.rb', line 26 def convert( value, to_type, default = nil ) begin name = "Gloo::Convert::#{value.class}To#{to_type}" clazz = name.split( '::' ).inject( Object ) { |o, c| o.const_get c } o = clazz.new return o.convert( value ) rescue => e @engine.log_exception e end return default end |