Module: Otto::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/otto/utils.rb

Overview

Utility methods for common operations and helpers

Instance Method Summary collapse

Instance Method Details

#nowTime

Returns Current time in UTC.

Returns:

  • (Time)

    Current time in UTC



11
12
13
# File 'lib/otto/utils.rb', line 11

def now
  Time.now.utc
end

#now_in_μsInteger Also known as: now_in_microseconds

Returns the current time in microseconds. This is used to measure the duration of Database commands.

Alias: now_in_microseconds

Returns:

  • (Integer)

    The current time in microseconds.



21
22
23
# File 'lib/otto/utils.rb', line 21

def now_in_μs
  Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
end

#yes?(value) ⇒ Boolean

Determine if a value represents a “yes” or true value

Examples: yes?(‘true’) # => true yes?(‘yes’) # => true yes?(‘1’) # => true

Parameters:

  • value (Object)

    The value to evaluate

Returns:

  • (Boolean)

    True if the value represents “yes”, false otherwise



35
36
37
# File 'lib/otto/utils.rb', line 35

def yes?(value)
  !value.to_s.empty? && %w[true yes 1].include?(value.to_s.downcase)
end