Sha256: f661193a842866fee5b0160dd7a425e5288d02608bdbf121338bfca6d9cc1fa1

Contents?: true

Size: 519 Bytes

Versions: 1

Compression:

Stored size: 519 Bytes

Contents

module RevealCK
  #
  # Public: A FileSlicer knows how to remove a section of a file.
  #
  class FileSlicer

    def self.remove!(slice_file, range)
      lines = File.open(slice_file).readlines
      slicer = FileSlicer.new lines
      sliced_lines = slicer.remove range
      File.open(slice_file, 'w') { |file| file << sliced_lines.join }
    end

    def initialize(lines)
      @lines = lines
    end

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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reveal-ck-0.1.6 lib/reveal-ck/file_slicer.rb