lib/banana_bits/concerns/hashable.rb in banana_bits-0.2.2 vs lib/banana_bits/concerns/hashable.rb in banana_bits-0.2.3
- old
+ new
@@ -2,19 +2,19 @@
module Concerns
module Hashable
def remove_blank_values(collection)
if collection.is_a?(Hash)
collection.each_with_object({}) do |(k, v), new_hash|
- if v.empty? && v != false
+ if v.blank?
new_hash.delete(k)
else
if v.is_a?(Hash)
new_hash[k] = remove_blank_values(v)
elsif v.is_a?(Array)
new_hash[k] = remove_blank_values_from_array!(v)
else
- new_hash[k] = v unless collection.empty?
+ new_hash[k] = v unless collection.blank?
end
end
end
elsif collection.is_a?(Array)
remove_blank_values_from_array(collection)
@@ -22,14 +22,14 @@
end
def remove_blank_values!(collection)
if collection.is_a?(Hash)
collection.each_pair do |k, v|
- if (v.empty? && v != false)
+ if v.blank?
collection.delete(k)
elsif v.is_a?(Hash)
remove_blank_values!(v)
- collection.delete(k) if collection[k].nil? || collection[k].empty?
+ collection.delete(k) if collection[k].blank?
elsif v.is_a?(Array)
remove_blank_values_from_array!(v)
end
end
elsif collection.is_a?(Array)