Class: Teems::Support::HelpFormatter
- Inherits:
-
Object
- Object
- Teems::Support::HelpFormatter
- Defined in:
- lib/teems/support/help_formatter.rb
Overview
Formats help text for commands
Defined Under Namespace
Classes: Section
Instance Method Summary collapse
- #build_help_lines ⇒ Object
- #description(text) ⇒ Object
-
#initialize(usage) ⇒ HelpFormatter
constructor
A new instance of HelpFormatter.
- #note(text) ⇒ Object
- #render ⇒ Object
- #section(title) {|section| ... } ⇒ Object
Constructor Details
#initialize(usage) ⇒ HelpFormatter
Returns a new instance of HelpFormatter.
7 8 9 10 11 12 |
# File 'lib/teems/support/help_formatter.rb', line 7 def initialize(usage) @usage = usage @description = nil @sections = [] @notes = [] end |
Instance Method Details
#build_help_lines ⇒ Object
34 35 36 37 38 39 |
# File 'lib/teems/support/help_formatter.rb', line 34 def build_help_lines lines = [@usage, ''] lines.push(@description, '') if @description @sections.each { |section| lines.push(section.render, '') } lines end |
#description(text) ⇒ Object
14 15 16 |
# File 'lib/teems/support/help_formatter.rb', line 14 def description(text) @description = text end |
#note(text) ⇒ Object
18 19 20 |
# File 'lib/teems/support/help_formatter.rb', line 18 def note(text) @notes << text end |
#render ⇒ Object
28 29 30 31 32 |
# File 'lib/teems/support/help_formatter.rb', line 28 def render lines = build_help_lines @notes.each { |note| lines << "Note: #{note}" } lines.join("\n") end |