Class: Exchange::Helper

Inherits:
Object
  • Object
show all
Extended by:
SingleForwardable
Includes:
Singleton
Defined in:
lib/exchange/helper.rb

Overview

Helper Functions that get used throughout the gem can be placed here

Author:

  • Beat Richartz

Since:

  • 0.3

Version:

  • 0.6

Instance Method Summary collapse

Instance Method Details

#assure_time(arg = nil, opts = {}) ⇒ Object

A helper function to assure a value is an instance of time

Parameters:

  • arg (Time, String, NilClass) (defaults to: nil)

    The value to be asserted

  • opts (Hash) (defaults to: {})

    Options for assertion

Options Hash (opts):

  • :default (Symbol)

    a method that can be sent to Time if the argument is nil (:now for example)

Since:

  • 0.3



21
22
23
24
25
26
27
# File 'lib/exchange/helper.rb', line 21

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