Module: DeepCover::Tools::Blank
- Defined in:
- lib/deep_cover/tools/blank.rb
Constant Summary collapse
- BLANK_RE =
/\A[[:space:]]*\z/
Instance Method Summary collapse
-
#blank?(obj) ⇒ Boolean
Homemade poor-man’s blank? Based, but modified, on github.com/rails/rails/blob/5-0-stable/activesupport/lib/active_support/core_ext/object/blank.rb.
- #presence(obj) ⇒ Object
- #present?(obj) ⇒ Boolean
Instance Method Details
#blank?(obj) ⇒ Boolean
Homemade poor-man’s blank? Based, but modified, on github.com/rails/rails/blob/5-0-stable/activesupport/lib/active_support/core_ext/object/blank.rb
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
17 18 19 |
# File 'lib/deep_cover/tools/blank.rb', line 17 def present?(obj) !blank?(obj) end |