Class: Yuzu::PostProcessors::AllCategoriesPostProcessor

Inherits:
PostProcessor show all
Defined in:
lib/yuzu/postprocessors/all_categories.rb

Instance Attribute Summary

Attributes inherited from PostProcessor

#name

Instance Method Summary collapse

Methods inherited from PostProcessor

#match, postprocessors, registry

Constructor Details

#initializeAllCategoriesPostProcessor

Returns a new instance of AllCategoriesPostProcessor.



7
8
9
# File 'lib/yuzu/postprocessors/all_categories.rb', line 7

def initialize
  @name = :all_categories
end

Instance Method Details

#default_value(website_file) ⇒ Object



14
15
16
# File 'lib/yuzu/postprocessors/all_categories.rb', line 14

def default_value(website_file)
  []
end

#get_value(website_file) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/yuzu/postprocessors/all_categories.rb', line 24

def get_value(website_file)
  cats = []
  found_names = []

  v = Yuzu::Core::Visitor.new(proc {|c| c.file?})
  v.traverse(website_file.root) do |f|
    # NOTE Because of Ruby's hashing algorithm, we'll get different results calling uniq on an
    # array with objects hashed against a simple string. The comparison doesn't produce truly
    # unique results, and the categories.uniq call isn't accurate or consistent.

    f.categories.each do |cat|
      if not found_names.include?(cat.name) and not cat.name == "uncategorized"
        found_names.push(cat.name)
        cats.push(cat)
      end
    end
  end

  cats.sort
end

#regexObject



11
12
# File 'lib/yuzu/postprocessors/all_categories.rb', line 11

def regex
end

#value(website_file) ⇒ Object



18
19
20
21
22
# File 'lib/yuzu/postprocessors/all_categories.rb', line 18

def value(website_file)
  # There should only be one set of categories no matter which WebsiteFile is asked to gather
  # them. So we can cache the value in this singleton.
  @value ||= get_value(website_file)
end