Class: Hanami::Utils::Blank Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/utils/blank.rb

Overview

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

Checks for blank

Since:

  • 0.8.0

Constant Summary collapse

STRING_MATCHER =

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.

Matcher for blank strings

Since:

  • 0.8.0

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

Class Method Summary collapse

Class Method Details

.blank?(object) ⇒ TrueClass, FalseClass

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.

Checks if object is blank

Examples:

Basic Usage

require 'hanami/utils/blank'

Hanami::Utils::Blank.blank?(Hanami::Utils::String.new('')) # => true
Hanami::Utils::Blank.blank?('  ')                          # => true
Hanami::Utils::Blank.blank?(nil)                           # => true
Hanami::Utils::Blank.blank?(Hanami::Utils::Hash.new({}))   # => true
Hanami::Utils::Blank.blank?(true)                          # => false
Hanami::Utils::Blank.blank?(1)                             # => false

Parameters:

  • object

    the argument

Returns:

  • (TrueClass, FalseClass)

    info, whether object is blank

Since:

  • 0.8.0



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hanami/utils/blank.rb', line 34

def self.blank?(object)
  case object
  when String, ::String
    STRING_MATCHER === object # rubocop:disable Style/CaseEquality
  when Hash, ::Hash, ::Array
    object.empty?
  when TrueClass, Numeric
    false
  when FalseClass, NilClass
    true
  else
    object.respond_to?(:empty?) ? object.empty? : !self
  end
end

.filled?(object) ⇒ TrueClass, FalseClass

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.

Checks if object is filled

Examples:

Basic Usage

require 'hanami/utils/blank'

Hanami::Utils::Blank.filled?(true)                          # => true
Hanami::Utils::Blank.filled?(1)                             # => true
Hanami::Utils::Blank.filled?(Hanami::Utils::String.new('')) # => false
Hanami::Utils::Blank.filled?('  ')                          # => false
Hanami::Utils::Blank.filled?(nil)                           # => false
Hanami::Utils::Blank.filled?(Hanami::Utils::Hash.new({}))   # => false

Parameters:

  • object

    the argument

Returns:

  • (TrueClass, FalseClass)

    whether the object is filled

Since:

  • 1.0.0



67
68
69
# File 'lib/hanami/utils/blank.rb', line 67

def self.filled?(object)
  !blank?(object)
end