Module: ShellTastic::Utils

Included in:
IO
Defined in:
lib/shelltastic/utils.rb

Instance Method Summary collapse

Instance Method Details

#empty_nil_blank?(str, raize = false) ⇒ Boolean, ShellTastic::CommandException

like the other methods but allow to set an exception flag

Parameters:

  • str (String)

    the string the needs to be checked

  • to (Boolean)

    raise an exception or not. DEFAULT is false

Returns:

Raises:



25
26
27
28
29
# File 'lib/shelltastic/utils.rb', line 25

def empty_nil_blank?(str, raize=false)
  result = (str !~ /[^[:space:]]/ || str.nil? || str.empty?)
  raise ShellTastic::CommandException.new("Command is emtpy or nil") if result and raize
  result
end

#string_nil_or_blank!(str) ⇒ ShellTastic::CommandException

Note:

the ‘!` it will raise an exception instead of returning a boolean

Parameters:

  • str (String)

    the string the needs to be checked

Returns:



13
14
15
16
17
18
# File 'lib/shelltastic/utils.rb', line 13

def string_nil_or_blank! str
  # raise if command is empty or nil
  if str !~ /[^[:space:]]/ || str.nil? || str.empty?
    raise ShellTastic::CommandException.new("Command is emtpy or nil")
  end
end

#string_nil_or_blank?(str) ⇒ Boolean

Parameters:

  • str (String)

    the string the needs to be checked

Returns:

  • (Boolean)


6
7
8
# File 'lib/shelltastic/utils.rb', line 6

def string_nil_or_blank? str
  str !~ /[^[:space:]]/ || str.nil? || str.empty?
end