Module: TpLinkSmartplug::Helpers

Included in:
Base, Device
Defined in:
lib/tp_link_smartplug/helpers.rb

Overview

Generic helper methods

Instance Method Summary collapse

Instance Method Details

#debug_message(string) ⇒ Object

Formats a message for output as a debug log

Parameters:

  • string (String)

    the message to be formatted for debug output



9
10
11
12
# File 'lib/tp_link_smartplug/helpers.rb', line 9

def debug_message(string)
  caller_method = caller_locations(1..1).first.label
  $stdout.puts(Time.now.strftime('%Y-%m-%d %H:%M:%S: ').concat("#{caller_method}: ").concat(string))
end

#nil_or_empty?(value) ⇒ Boolean

Tests a variable for nil or empty status

Parameters:

  • v

    the variable to be tested

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/tp_link_smartplug/helpers.rb', line 17

def nil_or_empty?(value)
  return true if value.nil? || (value.respond_to?(:empty?) && value.empty?)

  false
end