lib/jekyll/favicon/utils/configuration/compact.rb in jekyll-favicon-1.0.0.pre.1 vs lib/jekyll/favicon/utils/configuration/compact.rb in jekyll-favicon-1.0.0.pre.2

- old
+ new

@@ -8,51 +8,48 @@ module Compact def self.included(klass) klass.extend(ClassMethods) end - # Nil and empty remove from configurations - module ClassMethods - def compact(compactable) - case compactable - when Hash, Array - compact_deep(compactable) || compactable.class[] - else - compactable - end + def self.compact_deep(compactable) + case compactable + when Hash then compact_hash compactable + when Array then compact_array compactable + else compactable end + end - private + def self.compact_hash(hash) + compacted_hash = hash.each_with_object({}) do |(key, value), memo| + next unless (compacted = compact_deep(value)) - def compact_deep(compactable) - case compactable - when Hash then compact_hash compactable - when Array then compact_array compactable - else compactable - end + memo[key] = compacted end + compact_shallow compacted_hash + end - def compact_hash(hash) - compacted_hash = hash.each_with_object({}) do |(key, value), memo| - next unless (compacted = compact_deep(value)) + def self.compact_array(array) + compacted_array = array.each_with_object([]) do |value, memo| + next unless (compacted = compact_deep(value)) - memo[key] = compacted - end - compact_shallow compacted_hash + memo << compacted end + compact_shallow compacted_array + end - def compact_array(array) - compacted_array = array.each_with_object([]) do |value, memo| - next unless (compacted = compact_deep(value)) + def self.compact_shallow(compactable) + compactable.empty? ? nil : compactable.compact + end - memo << compacted + # Nil and empty remove from configurations + module ClassMethods + def compact(compactable) + case compactable + when Hash, Array + Compact.compact_deep(compactable) || compactable.class[] + else + compactable end - compact_shallow compacted_array - end - - # :reek:UtilityFunction - def compact_shallow(compactable) - compactable.empty? ? nil : compactable.compact end end end end end