lib/core/util/data.rb in nucleon-0.1.5 vs lib/core/util/data.rb in nucleon-0.1.6
- old
+ new
@@ -124,29 +124,29 @@
return YAML.dump(data)
end
#---
- def self.value(value)
+ def self.value(value, undefined_value = nil)
case value
when String
if undef?(value)
- value = nil
+ value = undefined_value
elsif true?(value)
value = true
elsif false?(value)
value = false
end
when Array
value.each_with_index do |item, index|
- value[index] = value(item)
+ value[index] = value(item, undefined_value)
end
when Hash
value.each do |key, data|
- value[key] = value(data)
+ value[key] = value(data, undefined_value)
end
end
return value
end
@@ -236,9 +236,25 @@
def self.clean(data, remove_empty = true)
data.keys.each do |key|
obj = data[key]
data.delete(key) if obj.nil? || ( remove_empty && obj.is_a?(Hash) && obj.empty? )
+ end
+ data
+ end
+
+ #---
+
+ def self.deep_clean(data, remove_empty = true)
+ data.keys.each do |key|
+ obj = data[key]
+
+ if obj.nil? || ( remove_empty && obj.is_a?(Hash) && obj.empty? )
+ data.delete(key)
+
+ elsif data[key].is_a?(Hash)
+ deep_clean(data[key], remove_empty)
+ end
end
data
end
#---