Adjust Snapshot#crop to work on already optimized lines
parent
22f076a366
commit
82fa03863d
@ -1,25 +0,0 @@
|
||||
class LineOptimizer
|
||||
|
||||
def optimize(line)
|
||||
return [] if line.empty?
|
||||
|
||||
text = [line[0].text]
|
||||
brush = line[0].brush
|
||||
|
||||
cells = []
|
||||
|
||||
line[1..-1].each do |cell|
|
||||
if cell.brush == brush
|
||||
text << cell.text
|
||||
else
|
||||
cells << Cell.new(text.join, brush)
|
||||
text, brush = [cell.text], cell.brush
|
||||
end
|
||||
end
|
||||
|
||||
cells << Cell.new(text.join, brush)
|
||||
|
||||
cells
|
||||
end
|
||||
|
||||
end
|
@ -1,29 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe LineOptimizer do
|
||||
|
||||
let(:line_optimizer) { described_class.new }
|
||||
|
||||
def brush(attrs)
|
||||
Brush.new(attrs)
|
||||
end
|
||||
|
||||
describe '#optimize' do
|
||||
let(:line) { [
|
||||
Cell.new('a', brush(fg: 1)),
|
||||
Cell.new('b', brush(fg: 1)),
|
||||
Cell.new('c', brush(fg: 2)),
|
||||
Cell.new('d', brush(fg: 3)),
|
||||
Cell.new('e', brush(fg: 3))
|
||||
] }
|
||||
|
||||
subject { line_optimizer.optimize(line) }
|
||||
|
||||
it { should eq([
|
||||
Cell.new('ab', brush(fg: 1)),
|
||||
Cell.new('c', brush(fg: 2)),
|
||||
Cell.new('de', brush(fg: 3))
|
||||
]) }
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue