-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1f87e0
commit ef61d35
Showing
5 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Prmd | ||
# For any tid bits, or core extension methods, without the "core" extension | ||
module Utils | ||
# For checking if the string contains only spaces | ||
BLANK_REGEX = /\A\s+\z/ | ||
|
||
def self.blank?(obj) | ||
if obj.nil? | ||
true | ||
elsif obj.is_a?(String) | ||
obj.empty? || !!(obj =~ BLANK_REGEX) | ||
elsif obj.respond_to?(:empty?) | ||
obj.empty? | ||
else | ||
false | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require_relative 'helpers' | ||
|
||
class UtilsTest < Minitest::Test | ||
def test_blank? | ||
assert_equal true, Prmd::Utils.blank?(nil) | ||
assert_equal true, Prmd::Utils.blank?([]) | ||
assert_equal true, Prmd::Utils.blank?({}) | ||
assert_equal true, Prmd::Utils.blank?("") | ||
assert_equal true, Prmd::Utils.blank?(" ") | ||
assert_equal true, Prmd::Utils.blank?(" ") | ||
assert_equal false, Prmd::Utils.blank?([nil]) | ||
assert_equal false, Prmd::Utils.blank?({ a: nil }) | ||
assert_equal false, Prmd::Utils.blank?("A") | ||
assert_equal false, Prmd::Utils.blank?(Object.new) | ||
end | ||
end |