Class: Relish::Command::Help::Formatter
- Inherits:
-
Object
- Object
- Relish::Command::Help::Formatter
- Defined in:
- lib/relish/commands/help.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
- #format ⇒ Object
- #format_usage(index) ⇒ Object
-
#initialize(command, hash) ⇒ Formatter
constructor
A new instance of Formatter.
- #max_usage_length ⇒ Object
Constructor Details
#initialize(command, hash) ⇒ Formatter
Returns a new instance of Formatter.
26 27 28 29 |
# File 'lib/relish/commands/help.rb', line 26 def initialize(command, hash) @command = command @usage, @description = *hash.to_a.flatten end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
24 25 26 |
# File 'lib/relish/commands/help.rb', line 24 def command @command end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
24 25 26 |
# File 'lib/relish/commands/help.rb', line 24 def description @description end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
24 25 26 |
# File 'lib/relish/commands/help.rb', line 24 def usage @usage end |
Instance Method Details
#format ⇒ Object
35 36 37 38 39 |
# File 'lib/relish/commands/help.rb', line 35 def format description.split("\n").each_with_index do |part, index| puts "#{format_usage(index)} # #{part}" end end |
#format_usage(index) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/relish/commands/help.rb', line 41 def format_usage(index) if index.zero? usage.ljust(max_usage_length) else " " * max_usage_length end end |
#max_usage_length ⇒ Object
49 50 51 |
# File 'lib/relish/commands/help.rb', line 49 def max_usage_length Dsl::HelpText.max_usage_length end |