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.
22 23 24 25 26 27 |
# File 'lib/votd/helper/command_line.rb', line 22 def (text, line_width = 40) separator = "=" * line_width = [separator, text.center(line_width), separator].join("\n") 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 |