Class: Slk::Support::HelpFormatter::Section
- Inherits:
-
Object
- Object
- Slk::Support::HelpFormatter::Section
- Defined in:
- lib/slk/support/help_formatter.rb
Overview
Represents a section within help output (OPTIONS, EXAMPLES, etc.)
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #action(name, description) ⇒ Object
- #example(command, description = nil) ⇒ Object
-
#initialize(title) ⇒ Section
constructor
A new instance of Section.
- #item(left, right) ⇒ Object
- #option(flags, description) ⇒ Object
- #render ⇒ Object
- #text(content) ⇒ Object
Constructor Details
#initialize(title) ⇒ Section
Returns a new instance of Section.
74 75 76 77 |
# File 'lib/slk/support/help_formatter.rb', line 74 def initialize(title) @title = title @items = [] end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
72 73 74 |
# File 'lib/slk/support/help_formatter.rb', line 72 def title @title end |
Instance Method Details
#action(name, description) ⇒ Object
84 85 86 87 |
# File 'lib/slk/support/help_formatter.rb', line 84 def action(name, description) @items << [:action, name, description] self end |
#example(command, description = nil) ⇒ Object
89 90 91 92 |
# File 'lib/slk/support/help_formatter.rb', line 89 def example(command, description = nil) @items << [:example, command, description] self end |
#item(left, right) ⇒ Object
94 95 96 97 |
# File 'lib/slk/support/help_formatter.rb', line 94 def item(left, right) @items << [:item, left, right] self end |
#option(flags, description) ⇒ Object
79 80 81 82 |
# File 'lib/slk/support/help_formatter.rb', line 79 def option(flags, description) @items << [:option, flags, description] self end |
#render ⇒ Object
104 105 106 107 108 109 |
# File 'lib/slk/support/help_formatter.rb', line 104 def render return [] if @items.empty? max_left = calculate_max_left_width @items.map { |type, left, right| format_item(type, left, right, max_left) } end |
#text(content) ⇒ Object
99 100 101 102 |
# File 'lib/slk/support/help_formatter.rb', line 99 def text(content) @items << [:text, content, nil] self end |