Sha256: afcdd2079318945baa60216cfb247f79cc998d8ca6e2c710f668f5601993f498

Contents?: true

Size: 500 Bytes

Versions: 3

Compression:

Stored size: 500 Bytes

Contents

class FileSlicer

  def self.remove!(path, range)
    slice_file = if File.exists? path
      path
    else
      File.expand_path(File.join(Dir.pwd, path))
    end
    lines = File.open(slice_file).readlines
    slicer = FileSlicer.new lines
    sliced_lines = slicer.remove range
    File.open(slice_file, 'w') { |f| f << sliced_lines.join }
  end

  def initialize(lines)
    @lines = lines
  end

  def remove(range)
    @lines.select.with_index { |line, index| ! range.cover? index }
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reveal-ck-0.1.2 lib/reveal-ck/file_slicer.rb
reveal-ck-0.1.1 lib/reveal-ck/file_slicer.rb
reveal-ck-0.1.0 lib/reveal-ck/file_slicer.rb