Sha256: 56299804418d2f574ed950dd538e56e5e5111cc7b6b406d84a85f4680e4a4859

Contents?: true

Size: 938 Bytes

Versions: 9

Compression:

Stored size: 938 Bytes

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2020 Eric Crane.  All rights reserved.
#
# Data conversion manager.
#

module Gloo
  module Convert
    class Converter

      # ---------------------------------------------------------------------
      #    Convert
      # ---------------------------------------------------------------------

      #
      # Convert the given value to the specified type,
      # or if no conversion is available, revert to default.
      #
      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
          $log.error e.message
          $engine.heap.error.set_to e.message
        end

        return default
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gloo-0.8.0 lib/gloo/convert/converter.rb
gloo-0.7.7 lib/gloo/convert/converter.rb
gloo-0.7.6 lib/gloo/convert/converter.rb
gloo-0.7.5 lib/gloo/convert/converter.rb
gloo-0.7.4 lib/gloo/convert/converter.rb
gloo-0.7.3 lib/gloo/convert/converter.rb
gloo-0.7.2 lib/gloo/convert/converter.rb
gloo-0.7.1 lib/gloo/convert/converter.rb
gloo-0.7.0 lib/gloo/convert/converter.rb