Class: Teems::Support::HelpFormatter::Section

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

Overview

Section within help text

Constant Summary collapse

ITEM_RENDERERS =
{
  option: ->(args) { "  #{args[0].ljust(20)} #{args[1]}" },
  item: ->(args) { "  #{args[0].ljust(20)} #{args[1]}" },
  text: ->(args) { "  #{args.first}" }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Section

Returns a new instance of Section.



49
50
51
52
# File 'lib/teems/support/help_formatter.rb', line 49

def initialize(title)
  @title = title
  @items = []
end

Instance Method Details

#item(label, description) ⇒ Object



58
59
60
# File 'lib/teems/support/help_formatter.rb', line 58

def item(label, description)
  @items << [:item, label, description]
end

#option(flags, description) ⇒ Object



54
55
56
# File 'lib/teems/support/help_formatter.rb', line 54

def option(flags, description)
  @items << [:option, flags, description]
end

#renderObject



66
67
68
69
70
# File 'lib/teems/support/help_formatter.rb', line 66

def render
  lines = ["#{@title}:"]
  @items.each { |type, *args| lines << render_item(type, args) }
  lines.join("\n")
end

#text(content) ⇒ Object



62
63
64
# File 'lib/teems/support/help_formatter.rb', line 62

def text(content)
  @items << [:text, content]
end