Class: Externals::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/externals/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, usage, summary = nil) ⇒ Command

Returns a new instance of Command.



6
7
8
9
10
11
12
13
14
# File 'lib/externals/command.rb', line 6

def initialize name, usage, summary = nil
  @name = name
  @usage = usage
  @summary = summary
  
  if !@summary
    @summary, @usage = @usage, @summary
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/externals/command.rb', line 5

def name
  @name
end

#summaryObject (readonly)

Returns the value of attribute summary.



5
6
7
# File 'lib/externals/command.rb', line 5

def summary
  @summary
end

#usageObject (readonly)

Returns the value of attribute usage.



5
6
7
# File 'lib/externals/command.rb', line 5

def usage
  @usage
end

Instance Method Details

#to_sObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/externals/command.rb', line 16

def to_s
  retval = StringIO.new
  retval.printf "%-16s", name
  if usage
    retval.printf "Usage: #{usage}\n"
  else
    dont_pad_first = true
  end
  
  summary.split(/\n/).each_with_index do |line, index|
    if index == 0 && dont_pad_first
      retval.printf "%s\n", line.strip
    else
      retval.printf "%16s%s\n", '', line.strip
    end
  end
  
  retval.printf "\n"
  retval.string
end