Class: Mycmd::Printer
- Inherits:
-
Object
- Object
- Mycmd::Printer
- Defined in:
- lib/mycmd/printer.rb
Constant Summary collapse
- BORDER =
"*" * 30
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#result ⇒ Object
Returns the value of attribute result.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(result, header = false) ⇒ Printer
constructor
A new instance of Printer.
- #print ⇒ Object
Constructor Details
#initialize(result, header = false) ⇒ Printer
Returns a new instance of Printer.
8 9 10 11 |
# File 'lib/mycmd/printer.rb', line 8 def initialize(result, header=false) @result = result.is_a?(Mysql2::Result) ? result_to_array(result) : result @header = result.is_a?(Mysql2::Result) ? result.fields : header end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
6 7 8 |
# File 'lib/mycmd/printer.rb', line 6 def header @header end |
#result ⇒ Object
Returns the value of attribute result.
6 7 8 |
# File 'lib/mycmd/printer.rb', line 6 def result @result end |
#width ⇒ Object
Returns the value of attribute width.
6 7 8 |
# File 'lib/mycmd/printer.rb', line 6 def width @width end |
Class Method Details
Instance Method Details
#print ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/mycmd/printer.rb', line 13 def print if @result.respond_to? :each set_width print_line(@header) if @header @result.each do |row| print_line(row) end end end |