module GorillaPatch::Blank

Adding blank methods

Constants

REFINED_ENUMERABLES

rubocop:disable Metrics/BlockLength

Public Instance Methods

blank?() click to toggle source
# File lib/gorilla_patch/blank.rb, line 9
def blank?
        strip.empty?
end
deep_reject_blank_strings_in(object) click to toggle source
# File lib/gorilla_patch/blank.rb, line 60
def deep_reject_blank_strings_in(object)
        case object
        when String
                object.strip
        when *REFINED_ENUMERABLES
                object.reject_blank_strings!
        else
                object
        end
end
deep_value_empty?(value) click to toggle source
# File lib/gorilla_patch/blank.rb, line 54
def deep_value_empty?(value)
        deep_reject_blank_strings_in(value).empty?
rescue NoMethodError
        false
end
nilify_blank_strings() click to toggle source
# File lib/gorilla_patch/blank.rb, line 35
def nilify_blank_strings
        result = map do |element|
                if element.is_a?(String) && element.blank?
                        nil
                elsif REFINED_ENUMERABLES.any? { |klass| element.is_a?(klass) }
                        element.nilify_blank_strings
                else
                        element
                end
        end
        is_a?(Hash) ? result.to_h : result
end
nilify_blank_strings!() click to toggle source
# File lib/gorilla_patch/blank.rb, line 48
def nilify_blank_strings!
        replace nilify_blank_strings
end
reject_blank_strings() click to toggle source
# File lib/gorilla_patch/blank.rb, line 77
def reject_blank_strings
        deep_dup.reject do |value|
                deep_value_empty? value
        end
end
reject_blank_strings!() click to toggle source
# File lib/gorilla_patch/blank.rb, line 31
def reject_blank_strings!
        replace reject_blank_strings
end