Class: Clamp::Help::Builder
- Inherits:
-
Object
- Object
- Clamp::Help::Builder
- Defined in:
- lib/clamp/help.rb
Constant Summary collapse
- DETAIL_FORMAT =
" %-29s %s".freeze
Instance Method Summary collapse
- #add_description(description) ⇒ Object
- #add_list(heading, items) ⇒ Object
- #add_usage(invocation_path, usage_descriptions) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #string ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
56 57 58 |
# File 'lib/clamp/help.rb', line 56 def initialize @out = StringIO.new end |
Instance Method Details
#add_description(description) ⇒ Object
71 72 73 74 75 |
# File 'lib/clamp/help.rb', line 71 def add_description(description) return unless description puts "" puts description.gsub(/^/, " ") end |
#add_list(heading, items) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/clamp/help.rb', line 79 def add_list(heading, items) puts "\n#{heading}:" items.reject { |i| i.respond_to?(:hidden?) && i.hidden? }.each do |item| label, description = item.help description.each_line do |line| puts format(DETAIL_FORMAT, label, line) label = "" end end end |
#add_usage(invocation_path, usage_descriptions) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/clamp/help.rb', line 64 def add_usage(invocation_path, usage_descriptions) puts Clamp.(:usage_heading) + ":" usage_descriptions.each do |usage| puts " #{invocation_path} #{usage}".rstrip end end |
#string ⇒ Object
60 61 62 |
# File 'lib/clamp/help.rb', line 60 def string @out.string end |