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
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

#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



51
52
53
54
# File 'lib/mycmd/printer.rb', line 51

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

Instance Method Details



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