Class: Relish::Command::Help::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/relish/commands/help.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commandObject (readonly)

Returns the value of attribute command.



23
24
25
# File 'lib/relish/commands/help.rb', line 23

def command
  @command
end

#descriptionObject (readonly)

Returns the value of attribute description.



23
24
25
# File 'lib/relish/commands/help.rb', line 23

def description
  @description
end

#usageObject (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

#formatObject



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_lengthObject



48
49
50
# File 'lib/relish/commands/help.rb', line 48

def max_usage_length
  Dsl::HelpText.max_usage_length
end