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 12 13 14 15 16 |
# File 'lib/mycmd/printer.rb', line 8 def initialize(result, header=false) @header = header if result.is_a? Mysql2::Result @result = result_to_array(result) @header = result.fields if @header else @result = result end 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
18 19 20 21 22 23 24 25 26 |
# File 'lib/mycmd/printer.rb', line 18 def print if @result.respond_to? :each set_width print_line(@header) if @header @result.each do |row| print_line(row) end end end |