Module: DeepCover::Tools::Blank

Defined in:
lib/deep_cover/tools/blank.rb

Constant Summary collapse

BLANK_RE =
/\A[[:space:]]*\z/

Instance Method Summary collapse

Instance Method Details

#blank?(obj) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/deep_cover/tools/blank.rb', line 9

def blank?(obj)
  if obj.is_a?(String)
    obj.empty? || obj =~ BLANK_RE
  else
    obj.respond_to?(:empty?) ? !!obj.empty? : !obj
  end
end

#presence(obj) ⇒ Object



21
22
23
# File 'lib/deep_cover/tools/blank.rb', line 21

def presence(obj)
  obj if present?(obj)
end

#present?(obj) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/deep_cover/tools/blank.rb', line 17

def present?(obj)
  !blank?(obj)
end