Class: FileSlicer
- Inherits:
-
Object
- Object
- FileSlicer
- Defined in:
- lib/reveal-ck/file_slicer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(lines) ⇒ FileSlicer
constructor
A new instance of FileSlicer.
- #remove(range) ⇒ Object
Constructor Details
#initialize(lines) ⇒ FileSlicer
Returns a new instance of FileSlicer.
15 16 17 |
# File 'lib/reveal-ck/file_slicer.rb', line 15 def initialize(lines) @lines = lines end |
Class Method Details
.remove!(path, range) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/reveal-ck/file_slicer.rb', line 3 def self.remove!(path, range) slice_file = if File.exists? path path else File.(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 |
Instance Method Details
#remove(range) ⇒ Object
19 20 21 |
# File 'lib/reveal-ck/file_slicer.rb', line 19 def remove(range) @lines.select.with_index { |line, index| ! range.cover? index } end |