Module: Alchemy::Tasks::Usage

Extended by:
Usage
Included in:
Usage
Defined in:
lib/alchemy/tasks/usage.rb

Instance Method Summary collapse

Instance Method Details

#elements_count_by_nameObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/alchemy/tasks/usage.rb', line 8

def elements_count_by_name
  res = Alchemy::Element.all
    .select("name, COUNT(*) AS count")
    .group(:name)
    .order("count DESC, name ASC")
    .map { |e| {"name" => e.name, "count" => e.count} }
  Alchemy::Element.definitions.map do |definition|
    count = res.find { |r| r["name"] == definition["name"] }&.fetch("count") || 0
    definition["count"] = count
    definition
  end.sort_by { |r| -1 * r["count"] }
end

#pages_count_by_typeObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/alchemy/tasks/usage.rb', line 21

def pages_count_by_type
  res = Alchemy::Page.all
    .select("page_layout, COUNT(*) AS count")
    .group(:page_layout)
    .order("count DESC, page_layout ASC")
    .map { |p| {"page_layout" => p.page_layout, "count" => p.count} }
  Alchemy::PageLayout.all.reject { |page_layout| res.map { |p| p["page_layout"] }.include? page_layout["name"] }.sort_by { |d| d["name"] }.each do |page_layout|
    res << {"page_layout" => page_layout["name"], "count" => 0}
  end
  res
end