Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront-cli/display/base.rb,
lib/wavefront-cli/commands/base.rb

Overview

Extensions to the String class to help with formatting.

Instance Method Summary collapse

Instance Method Details

#cmd_fold(width = TW, indent = 10) ⇒ Object

Fold long command lines. We can’t break on a space inside

square brackets

or it confuses docopt.



100
101
102
103
104
# File 'lib/wavefront-cli/commands/base.rb', line 100

def cmd_fold(width = TW, indent = 10)
  gsub(/\s(?=\w+\])/, '^').
  scan(/\S.{0,#{width - 8}}\S(?=\s|$)|\S+/).join("\n" + ' ' * indent).
  gsub('^', ' ')
end

#fold(width = TW, indent = 10) ⇒ Object

Fold long command lines and suitably indent



301
302
303
# File 'lib/wavefront-cli/display/base.rb', line 301

def fold(width = TW, indent = 10)
  scan(/\S.{0,#{width - 2}}\S(?=\s|$)|\S+/).join("\n" + ' ' * indent)
end