class Nineteen::Eighty::Two::Decorators::RunLengthEncoder

Public Class Methods

encode(row) click to toggle source
# File lib/nineteen/eighty/two/decorators/run_length_encoder.rb, line 6
def self.encode row
  result = []
  count = 0
  step = 0
  while step < row.length
    current = row[step]
    step += 1
    nxt = row[step]
    if nxt == current
      count += 1
    else
      result << (Span.new current, count + 1)
      count = 0
      current = nxt
    end
  end

  result
end