Permalink
Browse files

Tape#replace: expand if replaced range is out of duration

  • Loading branch information...
1 parent ff4884d commit 8afa6f35f970a32079ed45ff64cbdc56cb3778f0 @youpy committed Dec 8, 2012
Showing with 10 additions and 11 deletions.
  1. +7 −7 lib/scissor/tape.rb
  2. +3 −4 spec/scissor_spec.rb
View
@@ -5,7 +5,6 @@ module Scissor
class Tape
class Error < StandardError; end
class EmptyFragment < Error; end
- class OutOfDuration < Error; end
attr_reader :fragments
@@ -152,16 +151,17 @@ def replace(start, length, replaced)
new_instance = self.class.new
offset = start + length
- if offset > duration
- raise OutOfDuration
- end
+ new_instance += slice(0, start)
- if start > 0
- new_instance += slice(0, start)
+ if new_instance.duration < start
+ new_instance + Scissor.silence(start - new_instance.duration)
end
new_instance += replaced
- new_instance += slice(offset, duration - offset)
+
+ if duration > offset
+ new_instance += slice(offset, duration - offset)
+ end
new_instance
end
@@ -238,10 +238,9 @@
scissor.fragments.size.should eql(1)
end
- it "should raise error if replaced range is out of duration" do
- lambda {
- @mp3.slice(0, 100).replace(60, 41, @mp3.slice(0, 60))
- }.should raise_error(Scissor::Tape::OutOfDuration)
+ it "should expand if replaced range is out of duration" do
+ replaced = @mp3.slice(0, 100).replace(60, 41, @mp3.slice(0, 60))
+ replaced.duration.should eql(120.0)
end
it "should write to file and return new instance of Scissor" do

0 comments on commit 8afa6f3

Please sign in to comment.