Class: SpreenWiki::UnknownWikiCountListExporter

Inherits:
Application
  • Object
show all
Defined in:
lib/spreen_wiki/unknown_wiki_count_list_exporter.rb,
sig/generated/spreen_wiki/unknown_wiki_count_list_exporter.rbs

Overview

Writes a sorted text report of how many wikis exist under each of the configured "unknown owner/category" namespaces.

Constant Summary collapse

DEFAULT_OUTPUT_FILENAME =

Returns:

  • (::String)
'unknown_wiki_count_list_by_namespace.txt'

Instance Attribute Summary collapse

Attributes inherited from Application

#base_path, #config, #excluded_paths, #group_by, #home_overflow, #language, #path_to_home, #path_to_sidebar, #paths_to_wikis

Instance Method Summary collapse

Methods inherited from Application

#namespace_for, #no_declaration, #owned_wiki_maps, #parse_home_overflow, #plain_wiki_maps, #populate_namespace, run, #target_paths, #target_regexp, #validate!, #validate_home_overflow!, #wiki_maps_with_namespace

Constructor Details

#initialize(base_path: Dir.pwd, group_by: 'Owner', language: 'English', home_overflow: 'false', output: nil) ⇒ UnknownWikiCountListExporter

Returns a new instance of UnknownWikiCountListExporter.

Parameters:

  • base_path: (String) (defaults to: Dir.pwd)
  • group_by: (String) (defaults to: 'Owner')
  • language: (String) (defaults to: 'English')
  • home_overflow: (bool, String) (defaults to: 'false')
  • output: (String, nil) (defaults to: nil)
  • (Object)


19
20
21
22
23
# File 'lib/spreen_wiki/unknown_wiki_count_list_exporter.rb', line 19

def initialize(base_path: Dir.pwd, group_by: 'Owner', language: 'English', home_overflow: 'false',
               output: nil, **)
  super(base_path:, group_by:, language:, home_overflow:, **)
  @path_to_export = resolve_output_path(output || DEFAULT_OUTPUT_FILENAME)
end

Instance Attribute Details

#path_to_exportString (readonly)

: String

Returns:

  • (String)


33
34
35
# File 'lib/spreen_wiki/unknown_wiki_count_list_exporter.rb', line 33

def path_to_export
  @path_to_export
end

Instance Method Details

#count_list_by_namespaceArray[String]

Returns:

  • (Array[String])


52
53
54
55
56
57
# File 'lib/spreen_wiki/unknown_wiki_count_list_exporter.rb', line 52

def count_list_by_namespace
  @count_list_by_namespace ||= begin
    counts = plain_wiki_maps.slice(*namespace_list).map { |namespace, wikis| "#{namespace}: #{wikis.length}" }
    (counts + missing_count_list_by_namespace).sort
  end
end

#missing_count_list_by_namespaceArray[String]

Returns:

  • (Array[String])


47
48
49
# File 'lib/spreen_wiki/unknown_wiki_count_list_exporter.rb', line 47

def missing_count_list_by_namespace
  (namespace_list - plain_wiki_maps.keys).map { |namespace| "#{namespace}: 0" }
end

#namespace_listArray[String]

Returns:

  • (Array[String])


42
43
44
# File 'lib/spreen_wiki/unknown_wiki_count_list_exporter.rb', line 42

def namespace_list
  config.unknown_namespaces(group_by, language)
end

#resolve_output_path(filename) ⇒ String

Parameters:

  • filename (String)

Returns:

  • (String)


37
38
39
# File 'lib/spreen_wiki/unknown_wiki_count_list_exporter.rb', line 37

def resolve_output_path(filename)
  File.absolute_path?(filename) ? filename : File.join(base_path, filename)
end

#run[ Array[String], String ]

Returns:

  • ([ Array[String], String ])


26
27
28
29
# File 'lib/spreen_wiki/unknown_wiki_count_list_exporter.rb', line 26

def run
  File.open(path_to_export, 'wb') { |f| f.puts(count_list_by_namespace) }
  [count_list_by_namespace, path_to_export]
end