class Kafo::HelpBuilders::Base

Public Class Methods

new(params) click to toggle source
Calls superclass method
# File lib/kafo/help_builders/base.rb, line 12
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 17
def add_list(heading, items)
  return if items.empty?
  if heading == 'Options'
    line "\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 45
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 74
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 61
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 69
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 49
def header(level, text)
  level(level) + ' ' + text
end
level(n) click to toggle source
# File lib/kafo/help_builders/base.rb, line 57
def level(n)
  '=' * n
end
module_header(name) click to toggle source
# File lib/kafo/help_builders/base.rb, line 53
def module_header(name)
  "\n" + header(1, 'Module ' + name)
end
parametrization() click to toggle source
# File lib/kafo/help_builders/base.rb, line 86
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 82
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 39
def sorted_keys(modules_hash)
  keys = modules_hash.keys
  keys.reject! { |k| k == DEFAULT_MODULE_NAME }
  [ DEFAULT_MODULE_NAME ] + keys.sort
end