Sha256: 33bbf16e7228b177ce2229f91009b988b829d6ac16075e71690ec304beb8f9e0

Contents?: true

Size: 668 Bytes

Versions: 1

Compression:

Stored size: 668 Bytes

Contents

class Mangos::PagesDeflater
  def initialize(page_paths)
    @page_paths = page_paths
  end

  def deflate
    last_ext = nil
    last_base = nil
    last_count = 0

    out = []

    @page_paths.each do |path|
      base, ext = path.split(".")

      if last_base.nil? || (ext != last_ext) || (base != last_base.succ)
        if last_count > 0
          out.last.replace("#{out.last}/#{last_count}")
          last_count = 0
        end

        out << path
      else
        last_count += 1
      end

      last_base = base
      last_ext = ext
    end

    if last_count > 0
      out.last.replace("#{out.last}/#{last_count}")
    end

    out.join("|")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mangos-0.1 lib/mangos/pages_deflater.rb