module Votd::Helper::CommandLine

This module contains helper methods that support the command-line application

Public Instance Methods

banner(text, line_width=40) click to toggle source

Generates a text banner suitable for displaying from a command-line utility. @example

banner("My Banner", 20)

->
====================
     My Banner
====================

@param [Integer] line_width number of columns for width @param [String] text text to print inside the banner @return [nil]

word_wrap(text, line_width=40) click to toggle source

Word-wraps text to the specified column width. @param [String] text the text to be wrapped @param [Integer] line_width column width @return [String] wrapped text

# File lib/votd/helper/command_line.rb, line 33
def word_wrap(text, line_width=40)
  text.split("\n").collect do |line|
    line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
  end * "\n"
end