Class: Teems::Support::HelpFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/teems/support/help_formatter.rb

Overview

Formats help text for commands

Defined Under Namespace

Classes: Section

Instance Method Summary collapse

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_linesObject



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

#renderObject



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

#section(title) {|section| ... } ⇒ Object

Yields:



22
23
24
25
26
# File 'lib/teems/support/help_formatter.rb', line 22

def section(title)
  section = Section.new(title)
  yield section
  @sections << section
end