class Kafo::HelpBuilders::Base
Public Class Methods
new(params)
click to toggle source
Calls superclass method
# File lib/kafo/help_builders/base.rb, line 11 def initialize(params) super() @params = params end
Public Instance Methods
add_list(heading, items)
click to toggle source
Calls superclass method
# File lib/kafo/help_builders/base.rb, line 16 def add_list(heading, items) return if items.empty? if heading == 'Options' puts "\n#{heading}:" data = by_module(items) sorted_keys(data).each do |section| if section == DEFAULT_MODULE_NAME add_list(header(1, section), data[section]) else add_module(section, data[section]) end end else super end end
Private Instance Methods
add_module(name, items)
click to toggle source
# File lib/kafo/help_builders/base.rb, line 44 def add_module(name, items) raise NotImplementedError, 'add module not defined' end
by_module(help_items)
click to toggle source
# File lib/kafo/help_builders/base.rb, line 73 def by_module(help_items) data = Hash.new { |h, k| h[k] = [] } params_mapping(help_items).each do |item, param| data[param.nil? ? DEFAULT_MODULE_NAME : param.module_name].push item end data end
by_parameter_groups(items)
click to toggle source
# File lib/kafo/help_builders/base.rb, line 60 def by_parameter_groups(items) data = Hash.new { |h, k| h[k] = [] } params_mapping(items).each do |item, param| data[group(param)].push item end data end
group(param)
click to toggle source
# File lib/kafo/help_builders/base.rb, line 68 def group(param) name = param.groups.reverse.find { |group| group.include?('parameters') } name.nil? ? DEFAULT_GROUP_NAME : name.sub(IGNORE_IN_GROUP_NAME, '') end
header(level, text)
click to toggle source
# File lib/kafo/help_builders/base.rb, line 48 def header(level, text) level(level) + ' ' + text end
level(n)
click to toggle source
# File lib/kafo/help_builders/base.rb, line 56 def level(n) '=' * n end
module_header(name)
click to toggle source
# File lib/kafo/help_builders/base.rb, line 52 def module_header(name) "\n" + header(1, 'Module ' + name) end
parametrization()
click to toggle source
# File lib/kafo/help_builders/base.rb, line 85 def parametrization @parametrization ||= begin @params.inject({}) do |h,p| h.update(parametrize(p) => p, parametrize(p, 'reset-') => p) end end end
params_mapping(items)
click to toggle source
# File lib/kafo/help_builders/base.rb, line 81 def params_mapping(items) items.map { |i| [i, parametrization[i.help.first.strip]] } end
sorted_keys(modules_hash)
click to toggle source
sorts modules by name with leaving Generic as first one
# File lib/kafo/help_builders/base.rb, line 38 def sorted_keys(modules_hash) keys = modules_hash.keys keys.reject! { |k| k == DEFAULT_MODULE_NAME } [ DEFAULT_MODULE_NAME ] + keys.sort end