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
# 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.reject { |definition| res.map { |e| e["name"] }.include? definition["name"] }.sort_by { |d| d["name"] }.each do |definition|
    res << {"name" => definition["name"], "count" => 0}
  end
  res
end

#pages_count_by_typeObject



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

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