module HelpSections
Constants
- PLUGIN_SECTION
- SECTIONS
- SECTION_ORDER
Public Class Methods
Source
# File lib/help_sections.rb, line 117 def self.entries_for_section(section_id, entries:) section_id = section_id.to_s.strip.downcase return [] unless section?(section_id) entries .select { |entry| section_for_entry(entry) == section_id } .sort_by { |entry| entry[:command] } end
Source
# File lib/help_sections.rb, line 106 def self.group_entries(entries) grouped = entries.group_by { |entry| section_for_entry(entry) } SECTION_ORDER.each_with_object({}) do |section_id, result| section_entries = grouped[section_id] next if section_entries.nil? || section_entries.empty? result[section_id] = section_entries.sort_by { |entry| entry[:command] } end end
Source
# File lib/help_sections.rb, line 97 def self.plugin_basename(plugin) File.basename(plugin.to_s, ".rb") end
Source
# File lib/help_sections.rb, line 89 def self.section?(topic) SECTIONS.key?(topic.to_s.strip.downcase) end
Source
# File lib/help_sections.rb, line 93 def self.section_config(section_id) SECTIONS.fetch(section_id.to_s) end
Source
# File lib/help_sections.rb, line 101 def self.section_for_entry(entry) basename = plugin_basename(entry[:plugin]) PLUGIN_SECTION[basename] || "other" end
Source
# File lib/help_sections.rb, line 126 def self.section_index_line(section_id, count:) config = section_config(section_id) "!help #{section_id} — #{config[:blurb]} (#{count})" end
Source
# File lib/help_sections.rb, line 131 def self.section_index_lines(grouped) grouped.map do |section_id, section_entries| section_index_line(section_id, count: section_entries.length) end end