Sha256: 30771a17d6383336b4f77c0d592e3402a0b1d4daed522d4a5b0515d96ad3c2ec

Contents?: true

Size: 610 Bytes

Versions: 3

Compression:

Stored size: 610 Bytes

Contents

module RevealCK
  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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reveal-ck-0.1.5 lib/reveal-ck/file_slicer.rb
reveal-ck-0.1.4 lib/reveal-ck/file_slicer.rb
reveal-ck-0.1.3 lib/reveal-ck/file_slicer.rb