You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asciinema.org/app/services/line_optimizer.rb

26 lines
409 B
Ruby

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