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.
25 26 27 28 |
# File 'lib/relish/commands/help.rb', line 25 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.
23 24 25 |
# File 'lib/relish/commands/help.rb', line 23 def command @command end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
23 24 25 |
# File 'lib/relish/commands/help.rb', line 23 def description @description end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
23 24 25 |
# File 'lib/relish/commands/help.rb', line 23 def usage @usage end |
Instance Method Details
#format ⇒ Object
34 35 36 37 38 |
# File 'lib/relish/commands/help.rb', line 34 def format description.split("\n").each_with_index do |part, index| puts "#{format_usage(index)} # #{part}" end end |
#format_usage(index) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/relish/commands/help.rb', line 40 def format_usage(index) if index.zero? usage.ljust(max_usage_length) else " " * max_usage_length end end |
#max_usage_length ⇒ Object
48 49 50 |
# File 'lib/relish/commands/help.rb', line 48 def max_usage_length Dsl::HelpText.max_usage_length end |