Class: SpreenWiki::UnknownWikiCountListExporter
- Inherits:
-
Application
- Object
- Application
- SpreenWiki::UnknownWikiCountListExporter
- 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 =
'unknown_wiki_count_list_by_namespace.txt'
Instance Attribute Summary collapse
-
#path_to_export ⇒ String
readonly
: String.
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
- #count_list_by_namespace ⇒ Array[String]
-
#initialize(base_path: Dir.pwd, group_by: 'Owner', language: 'English', home_overflow: 'false', output: nil) ⇒ UnknownWikiCountListExporter
constructor
A new instance of UnknownWikiCountListExporter.
- #missing_count_list_by_namespace ⇒ Array[String]
- #namespace_list ⇒ Array[String]
- #resolve_output_path(filename) ⇒ String
- #run ⇒ [ Array[String], String ]
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.
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_export ⇒ String (readonly)
: 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_namespace ⇒ 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_namespace ⇒ 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_list ⇒ 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
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 ]
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 |