Module: Dux::Blankness Private

Included in:
Dux
Defined in:
lib/dux/blankness.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Object#blank? and Object#present? replacements for when working outside of ActiveSupport.

Constant Summary collapse

WHITESPACE_ONLY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

A string containing only whitespace (as defined by unicode).

/\A[[:space:]]+\z/

Instance Method Summary collapse

Instance Method Details

#blankish?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if a provided object is semantically empty.

Parameters:

  • value (Object)

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dux/blankness.rb', line 15

def blankish?(value)
  case value
  when nil, false
    true
  when Dux[:nan?]
    true
  when String, Symbol
    value.empty? || value =~ WHITESPACE_ONLY
  when Dux[:blank?]
    value.blank?
  when Hash
    value.empty?
  when Array, Enumerable
    Dux.attempt(value, :empty?) || value.all? { |val| blankish?(val) }
  when Dux[:empty?]
    value.empty?
  else
    false
  end
end

#presentish?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Boolean complement of #blankish?

Parameters:

  • value (Object)

Returns:

  • (Boolean)


39
40
41
# File 'lib/dux/blankness.rb', line 39

def presentish?(value)
  !blankish?(value)
end