Module: Jekyll::Favicon::Utils::Configuration::Compact

Included in:
Jekyll::Favicon::Utils
Defined in:
lib/jekyll/favicon/utils/configuration/compact.rb

Overview

Favicon configuration compact logic

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.compact_array(array) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/jekyll/favicon/utils/configuration/compact.rb', line 30

def self.compact_array(array)
  compacted_array = array.each_with_object([]) do |value, memo|
    next unless (compacted = compact_deep(value))

    memo << compacted
  end
  compact_shallow compacted_array
end

.compact_deep(compactable) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/jekyll/favicon/utils/configuration/compact.rb', line 13

def self.compact_deep(compactable)
  case compactable
  when Hash then compact_hash compactable
  when Array then compact_array compactable
  else compactable
  end
end

.compact_hash(hash) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/jekyll/favicon/utils/configuration/compact.rb', line 21

def self.compact_hash(hash)
  compacted_hash = hash.each_with_object({}) do |(key, value), memo|
    next unless (compacted = compact_deep(value))

    memo[key] = compacted
  end
  compact_shallow compacted_hash
end

.compact_shallow(compactable) ⇒ Object



39
40
41
# File 'lib/jekyll/favicon/utils/configuration/compact.rb', line 39

def self.compact_shallow(compactable)
  compactable.empty? ? nil : compactable.compact
end

.included(klass) ⇒ Object



9
10
11
# File 'lib/jekyll/favicon/utils/configuration/compact.rb', line 9

def self.included(klass)
  klass.extend(ClassMethods)
end