Module: Votd::Helper::CommandLine
Overview
This module contains helper methods that support the command-line application
Instance Method Summary collapse
-
#banner(text, line_width = 40) ⇒ nil
Generates a text banner suitable for displaying from a command-line utility.
-
#word_wrap(text, line_width = 40) ⇒ String
Word-wraps text to the specified column width.
Instance Method Details
#banner(text, line_width = 40) ⇒ nil
Generates a text banner suitable for displaying from a command-line utility.
19 20 21 22 23 24 25 26 27 |
# File 'lib/votd/helper/command_line.rb', line 19 def (text, line_width=40) = "=" * line_width << "\n" << text.center(line_width) << "\n" << "=" * line_width puts nil end |
#word_wrap(text, line_width = 40) ⇒ String
Word-wraps text to the specified column width.
33 34 35 36 37 |
# 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 |