Class: Mycmd::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/mycmd/printer.rb

Constant Summary collapse

BORDER =
"*" * 30

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#headerObject

Returns the value of attribute header.



6
7
8
# File 'lib/mycmd/printer.rb', line 6

def header
  @header
end

#resultObject

Returns the value of attribute result.



6
7
8
# File 'lib/mycmd/printer.rb', line 6

def result
  @result
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/mycmd/printer.rb', line 6

def width
  @width
end

Class Method Details



46
47
48
49
# File 'lib/mycmd/printer.rb', line 46

def print_title(title, empty_line=false)
  puts if empty_line
  puts "#{BORDER}\n#{title}\n#{BORDER}"
end

Instance Method Details



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