From 653f0cca461a5c91d88ccda5ad610b4823d91773 Mon Sep 17 00:00:00 2001 From: Nick Palaniuk Date: Tue, 29 Mar 2016 20:50:30 -0400 Subject: [PATCH] Remove white space --- lib/terminal-table/cell.rb | 33 ++++++++++++++++----------------- lib/terminal-table/separator.rb | 6 +++--- lib/terminal-table/style.rb | 1 - lib/terminal-table/table.rb | 1 - spec/table_spec.rb | 16 ++++++++-------- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/lib/terminal-table/cell.rb b/lib/terminal-table/cell.rb index afd0811..831fabb 100644 --- a/lib/terminal-table/cell.rb +++ b/lib/terminal-table/cell.rb @@ -1,20 +1,19 @@ - module Terminal class Table class Cell ## # Cell value. - + attr_reader :value - + ## # Column span. - + attr_reader :colspan - + ## # Initialize with _options_. - + def initialize options = nil @value, options = options, {} unless Hash === options @value = options.fetch :value, value @@ -24,15 +23,15 @@ def initialize options = nil @index = options.fetch :index @table = options.fetch :table end - + def alignment? !@alignment.nil? end - + def alignment @alignment || @table.style.alignment || :left end - + def alignment=(val) supported = %w(left center right) if supported.include?(val.to_s) @@ -41,7 +40,7 @@ def alignment=(val) raise "Aligment must be one of: #{supported.join(' ')}" end end - + def align(val, position, length) positions = { :left => :ljust, :right => :rjust, :center => :center } val.public_send(positions[position], length) @@ -49,10 +48,10 @@ def align(val, position, length) def lines @value.to_s.split(/\n/) end - + ## # Render the cell. - + def render(line = 0) left = " " * @table.style.padding_left right = " " * @table.style.padding_right @@ -60,18 +59,18 @@ def render(line = 0) align("#{left}#{lines[line]}#{right}", alignment, render_width + @table.cell_padding) end alias :to_s :render - + ## # Returns the longest line in the cell and # removes all ANSI escape sequences (e.g. color) - + def value_for_column_width_recalc lines.map{ |s| escape(s) }.max_by{ |s| s.size } end - + ## # Returns the width of this cell - + def width padding = (colspan - 1) * @table.cell_spacing inner_width = (1..@colspan).to_a.inject(0) do |w, counter| @@ -81,7 +80,7 @@ def width end ## - # removes all ANSI escape sequences (e.g. color) + # removes all ANSI escape sequences (e.g. color) def escape(line) line.to_s.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, ''). gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, ''). diff --git a/lib/terminal-table/separator.rb b/lib/terminal-table/separator.rb index 103d5b8..f09c2f7 100644 --- a/lib/terminal-table/separator.rb +++ b/lib/terminal-table/separator.rb @@ -1,14 +1,14 @@ module Terminal class Table class Separator < Row - + def render arr_x = (0...@table.number_of_columns).to_a.map do |i| - @table.style.border_x * (@table.column_width(i) + @table.cell_padding) + @table.style.border_x * (@table.column_width(i) + @table.cell_padding) end border_i = @table.style.border_i border_i + arr_x.join(border_i) + border_i end end end -end \ No newline at end of file +end diff --git a/lib/terminal-table/style.rb b/lib/terminal-table/style.rb index 289c82f..9811a16 100644 --- a/lib/terminal-table/style.rb +++ b/lib/terminal-table/style.rb @@ -1,4 +1,3 @@ - module Terminal class Table # A Style object holds all the formatting information for a Table object diff --git a/lib/terminal-table/table.rb b/lib/terminal-table/table.rb index 14b4074..d190e14 100755 --- a/lib/terminal-table/table.rb +++ b/lib/terminal-table/table.rb @@ -1,4 +1,3 @@ - module Terminal class Table diff --git a/spec/table_spec.rb b/spec/table_spec.rb index fe1b03e..aca36d7 100755 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -546,11 +546,11 @@ module Terminal @table.render.should == <<-EOF.strip --------------- - name values + name values --------------- - a 1 2 3 - b 4 5 6 - c 7 8 9 + a 1 2 3 + b 4 5 6 + c 7 8 9 --------------- EOF end @@ -564,11 +564,11 @@ module Terminal @table.render.should == <<-EOF - name values + name values - a 1 2 3 - b 4 5 6 - c 7 8 9 + a 1 2 3 + b 4 5 6 + c 7 8 9 EOF end