Class: Rack::App::CLI::DefaultCommands::ListCommands::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/app/cli/default_commands/list_commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(known_commands) ⇒ Formatter

Returns a new instance of Formatter.



13
14
15
# File 'lib/rack/app/cli/default_commands/list_commands.rb', line 13

def initialize(known_commands)
  @rjust = known_commands.keys.push(*PRESERVED_KEYWORDS).map(&:to_s).map(&:length).max + 3
end

Instance Method Details

#command_suggestion_line_by(name, desc) ⇒ Object



17
18
19
# File 'lib/rack/app/cli/default_commands/list_commands.rb', line 17

def command_suggestion_line_by(name, desc)
  [name.to_s.rjust(@rjust), desc].join('  ')
end

#format(collection_hash) ⇒ Object



21
22
23
24
25
# File 'lib/rack/app/cli/default_commands/list_commands.rb', line 21

def format(collection_hash)
  collection_hash.to_a.sort_by{ |k, v| k.to_s }.map do |name, desc|
    command_suggestion_line_by(name, desc)
  end.join("\n")
end