Class: Hipe::GitHelper::Command
- Inherits:
-
Object
- Object
- Hipe::GitHelper::Command
- Defined in:
- lib/hipe-githelper.rb
Class Method Summary collapse
-
.wordwrap(text, line_width) ⇒ Object
thansks rails.
Instance Method Summary collapse
- #help_short(opts) ⇒ Object
-
#initialize(name, desc, ast) ⇒ Command
constructor
A new instance of Command.
- #syntax ⇒ Object
Constructor Details
#initialize(name, desc, ast) ⇒ Command
Returns a new instance of Command.
54 55 56 |
# File 'lib/hipe-githelper.rb', line 54 def initialize name, desc, ast @name, @desc, @ast = name, desc, ast end |
Class Method Details
.wordwrap(text, line_width) ⇒ Object
thansks rails
67 68 69 70 71 |
# File 'lib/hipe-githelper.rb', line 67 def self.wordwrap text, line_width # thansks rails text.split("\n").collect do |line| line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line end * "\n" end |
Instance Method Details
#help_short(opts) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/hipe-githelper.rb', line 58 def help_short opts buffer = opts[:buffer] || '' col1width,col2width = opts[:col1width], opts[:col2width] syntax = sprintf(%{ %-#{col1width-3}s },@ast.syntax) buffer << syntax (buffer << ("\n" + ' ' * col1width )) if syntax.length > (col1width) buffer << self.class.wordwrap(@desc,col2width).gsub(/$\n/,"\n"+' '*col1width) buffer end |
#syntax ⇒ Object
57 |
# File 'lib/hipe-githelper.rb', line 57 def syntax; @symbol.syntax; end |