Module: Choice::Writer
- Defined in:
- lib/choice/writer.rb
Overview
This module writes to the screen. As of now, its only real use is writing the help screen.
Constant Summary collapse
- SHORT_LENGTH =
Some constants used for printing and line widths
6
- SHORT_BREAK_LENGTH =
2
- LONG_LENGTH =
29
- PRE_DESC_LENGTH =
SHORT_LENGTH + SHORT_BREAK_LENGTH + LONG_LENGTH
Class Method Summary collapse
-
.help(args, target = STDOUT, dont_exit = false) ⇒ Object
The main method.
-
.print(str) ⇒ Object
Fake print – just add to target, which may not be STDOUT.
-
.printf(format, *args) ⇒ Object
Fake printf.
-
.puts(str = nil) ⇒ Object
Fake puts.
Class Method Details
.help(args, target = STDOUT, dont_exit = false) ⇒ Object
The main method. Takes a hash of arguments with the following possible keys, running them through the appropriate method:
banner, header, options, footer
Can also be told where to print (default STDOUT) and not to exit after printing the help screen, which it does by default.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/choice/writer.rb', line 19 def self.help(args, target = STDOUT, dont_exit = false) # Set our printing target. self.target = target # The banner method needs to know about the passed options if it's going # to do its magic. Only really needs :options if :banner is nil. (args[:banner], args[:options]) # Run these three methods, passing in the appropriate hash element. %w[header options footer].each do |meth| send(meth, args[meth.to_sym]) end # Exit. Unless you don't want to. exit unless dont_exit end |
.print(str) ⇒ Object
Fake print – just add to target, which may not be STDOUT.
182 183 184 |
# File 'lib/choice/writer.rb', line 182 def print(str) target << str end |
.printf(format, *args) ⇒ Object
Fake printf
177 178 179 |
# File 'lib/choice/writer.rb', line 177 def printf(format, *args) print(sprintf(format, *args)) end |
.puts(str = nil) ⇒ Object
Fake puts
171 172 173 174 |
# File 'lib/choice/writer.rb', line 171 def puts(str = nil) str = '' if str.nil? print(str + "\n") end |