Class: Kamaze::Project::Tools::Console::Output
- Defined in:
- lib/kamaze/project/tools/console/output.rb,
lib/kamaze/project/tools/console/output/buffer.rb
Overview
Provide a console output
Console output can be initialized from a IO
(STDOUT
and/or STDERR
)
a File
, using File.open()
, or a StringIO
.
As a result, console provides a convenient way to suppress or replace standard outputs (keeping them untouched).
Console output uses cli-ui
to provide colored formatting.
Defined Under Namespace
Classes: Buffer
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
protected
Returns the value of attribute output.
Instance Method Summary collapse
-
#bufferize(*strings) ⇒ Array<String>
protected
Bufferize given arguments.
-
#flush ⇒ self
Flushes any buffered data to the underlying operating system.
-
#formattable_on?(method) ⇒ Boolean
protected
Denote given method is formattable.
-
#formattables ⇒ Array<Symbol>
protected
Formattable methods.
-
#initialize(to = $stdout) ⇒ Output
constructor
A new instance of Output.
- #method_missing(method, *args, &block) ⇒ Object
-
#puts(s) ⇒ nil
Writes the given objects to
ios
as withIO#print
. - #respond_to_missing?(method, include_private = false) ⇒ Boolean
-
#tty? ⇒ Boolean
Denote is a tty.
Constructor Details
#initialize(to = $stdout) ⇒ Output
Returns a new instance of Output.
27 28 29 |
# File 'lib/kamaze/project/tools/console/output.rb', line 27 def initialize(to = $stdout) @output = to end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/kamaze/project/tools/console/output.rb', line 50 def method_missing(method, *args, &block) if respond_to_missing?(method) args = bufferize(*args) if formattable_on?(method.to_sym) return output.public_send(method, *args, &block) end super end |
Instance Attribute Details
#output ⇒ Object (readonly, protected)
Returns the value of attribute output.
97 98 99 |
# File 'lib/kamaze/project/tools/console/output.rb', line 97 def output @output end |
Instance Method Details
#bufferize(*strings) ⇒ Array<String> (protected)
Bufferize given arguments
117 118 119 |
# File 'lib/kamaze/project/tools/console/output.rb', line 117 def bufferize(*strings) strings.to_a.map { |s| Buffer.new(self, s) } end |
#flush ⇒ self
Flushes any buffered data to the underlying operating system
note that this is Ruby internal buffering only; the OS may buffer the data as well
44 45 46 47 48 |
# File 'lib/kamaze/project/tools/console/output.rb', line 44 def flush output.flush if output.respond_to?(:flush) self end |
#formattable_on?(method) ⇒ Boolean (protected)
Denote given method is formattable
109 110 111 |
# File 'lib/kamaze/project/tools/console/output.rb', line 109 def formattable_on?(method) formattables.include?(method.to_sym) end |
#formattables ⇒ Array<Symbol> (protected)
Formattable methods
102 103 104 |
# File 'lib/kamaze/project/tools/console/output.rb', line 102 def formattables [:puts, :print, :write] end |
#puts(s) ⇒ nil
Writes the given objects to ios
as with IO#print
.
Writes a record separator (typically a newline) after any that do not already end with a newline sequence. If called with an array argument, writes each element on a new line. If called without arguments, outputs a single record separator.
|
# File 'lib/kamaze/project/tools/console/output.rb', line 66
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
60 61 62 63 64 |
# File 'lib/kamaze/project/tools/console/output.rb', line 60 def respond_to_missing?(method, include_private = false) return true if output.respond_to?(method, include_private) super(method, include_private) end |
#tty? ⇒ Boolean
Denote is a tty
34 35 36 |
# File 'lib/kamaze/project/tools/console/output.rb', line 34 def tty? output.respond_to?(:'tty?') ? output.tty? : false end |