Sha256: 4b6af38920b55a37b78af1603d35b1cf6a14488f3538bc5c648e4ff4304f02ac

Contents?: true

Size: 904 Bytes

Versions: 7

Compression:

Stored size: 904 Bytes

Contents

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

7 entries across 7 versions & 1 rubygems

Version Path
exchange-0.12.0 lib/exchange/helper.rb
exchange-0.11.0 lib/exchange/helper.rb
exchange-0.10.2 lib/exchange/helper.rb
exchange-0.10.1 lib/exchange/helper.rb
exchange-0.10.0 lib/exchange/helper.rb
exchange-0.9.0 lib/exchange/helper.rb
exchange-0.8.0 lib/exchange/helper.rb