Skip to content

Commit

Permalink
Use the terminal-table gem to output tables in the shell
Browse files Browse the repository at this point in the history
  • Loading branch information
smtlaissezfaire committed Oct 11, 2009
1 parent 58cf498 commit c79b88c
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 395 deletions.
6 changes: 0 additions & 6 deletions lib/guillotine/shell/output_formatter.rb
Expand Up @@ -2,13 +2,7 @@ module Guillotine
module Shell
class OutputFormatter
dir = File.dirname(__FILE__) + "/output_formatter"
autoload :ColumnOutputer, "#{dir}/column_outputer"
autoload :ColumnDelimiterHeader, "#{dir}/column_delimiter_header"
autoload :ColumnExtractor, "#{dir}/column_extractor"
autoload :ColumnLengthCalculator, "#{dir}/column_length_calculator"
autoload :TableOutputer, "#{dir}/table_outputer"
autoload :OutputBuffer, "#{dir}/output_buffer"
autoload :RowAdder, "#{dir}/row_adder"

EMPTY_SET_STRING = "Empty set"

Expand Down
29 changes: 0 additions & 29 deletions lib/guillotine/shell/output_formatter/column_delimiter_header.rb

This file was deleted.

28 changes: 0 additions & 28 deletions lib/guillotine/shell/output_formatter/column_extractor.rb

This file was deleted.

28 changes: 0 additions & 28 deletions lib/guillotine/shell/output_formatter/column_length_calculator.rb

This file was deleted.

54 changes: 0 additions & 54 deletions lib/guillotine/shell/output_formatter/column_outputer.rb

This file was deleted.

44 changes: 0 additions & 44 deletions lib/guillotine/shell/output_formatter/output_buffer.rb

This file was deleted.

40 changes: 0 additions & 40 deletions lib/guillotine/shell/output_formatter/row_adder.rb

This file was deleted.

35 changes: 13 additions & 22 deletions lib/guillotine/shell/output_formatter/table_outputer.rb
@@ -1,38 +1,29 @@
require "terminal-table"

module Guillotine
module Shell
class OutputFormatter
class TableOutputer
include Terminal::Table::TableHelper

def initialize(table)
@table = table
@out_buffer = OutputBuffer.new
end

def column_names
@column_names ||= @table.first.keys
end

def output
last_column_name = column_names.last
column_names.each do |column_name|
add_column(column_name)
end
@out_buffer.to_s
end

def last_column_name
@last_column_name ||= column_names.last
end

def last_column?(column_name)
last_column_name == column_name
end

def add_column(column_name)
RowAdder.new(column_name, extractor_for(column_name), @out_buffer).add(last_column?(column_name))
end

def extractor_for(column_name)
@extractor = ColumnExtractor.new.extract(column_name, @table)
table do |t|
t.headings = column_names

@table.each do |record|
t << column_names.map do |col|
record[col]
end
end
end.to_s
end
end
end
Expand Down

This file was deleted.

45 changes: 0 additions & 45 deletions spec/guillotine/shell/output_formatter/column_extractor_spec.rb

This file was deleted.

This file was deleted.

0 comments on commit c79b88c

Please sign in to comment.