Module: Revolut::Utils

Defined in:
lib/revolut/utils.rb

Overview

Custom utilities

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.blank?(obj) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
# File 'lib/revolut/utils.rb', line 9

def blank?(obj)
  return !!BLANK_RE.match(obj) if obj.is_a?(String)

  obj.respond_to?(:empty?) ? !!obj.empty? : !obj
end

.presence(obj) ⇒ Object



19
20
21
# File 'lib/revolut/utils.rb', line 19

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

.present?(obj) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/revolut/utils.rb', line 15

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