Sha256: 60ce65bd5ae8c295af1afb21fe31bc8d643a0a58b16217d0867ca526512d16a3

Contents?: true

Size: 931 Bytes

Versions: 5

Compression:

Stored size: 931 Bytes

Contents

# -*- encoding : utf-8 -*-
require 'singleton'
require 'forwardable'

module Exchange
  
  # Helper Functions that get used throughout the gem can be placed here
  # @author Beat Richartz
  # @version 0.6
  # @since 0.3
  #
  class Helper
    include Singleton
    extend SingleForwardable
    
    # A helper function to assure a value is an instance of time
    # @param [Time, String, NilClass] arg The value to be asserted
    # @param [Hash] opts Options for assertion
    # @option opts [Symbol] :default a method that can be sent to Time if the argument is nil (:now for example)
    #
    def assure_time arg=nil, opts={}
      if arg
        arg.kind_of?(Time) ? arg : Time.gm(*arg.split('-'))
      elsif opts[:default]
        Time.send(opts[:default])
      end
    end
    
    # Forwards the assure_time method to the instance using singleforwardable
    #
    def_delegator :instance, :assure_time
    
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
exchange-1.2.2 lib/exchange/helper.rb
exchange-1.2.1 lib/exchange/helper.rb
exchange-1.2.0 lib/exchange/helper.rb
exchange-1.1.1 lib/exchange/helper.rb
exchange-1.1.0 lib/exchange/helper.rb