[rubyripper] push by boukewou...@gmail.com - Started on isolating the ripping logic into a RipStrategy class. on 2013-06-15 17:08 GMT

8 views
Skip to first unread message

rubyr...@googlecode.com

unread,
Jun 15, 2013, 1:09:01 PM6/15/13
to rubyrippe...@googlegroups.com
Revision: bb6c91762118
Author: Bouke Woudstra <boukew...@gmail.com>
Date: Sat Jun 15 10:07:32 2013
Log: Started on isolating the ripping logic into a RipStrategy class.

http://code.google.com/p/rubyripper/source/detail?r=bb6c91762118

Added:
/lib/rubyripper/datamodel/disc.rb
/lib/rubyripper/datamodel/track.rb
/lib/rubyripper/disc/ripStrategy.rb
/spec/disc/RipStrategy_spec.rb

=======================================
--- /dev/null
+++ /lib/rubyripper/datamodel/disc.rb Sat Jun 15 10:07:32 2013
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+# Rubyripper - A secure ripper for Linux/BSD/OSX
+# Copyright (C) 2013 Bouke Woudstra (boukew...@gmail.com)
+#
+# This file is part of Rubyripper. Rubyripper is free software: you can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+require 'rubyripper/datamodel/track'
+
+# This class stores all disc data
+module Datamodel
+ class Disc
+ def initialize
+ @tracks = Hash.new()
+ end
+
+ def getTrack(tracknumber)
+ @tracks[tracknumber]
+ end
+
+ def addTrack(number, startSector, lengthSector)
+ @tracks[number] = Track.new()
+ @tracks[number].number = number
+ @tracks[number].startSector = startSector
+ @tracks[number].lengthSector = lengthSector
+ end
+ end
+end
=======================================
--- /dev/null
+++ /lib/rubyripper/datamodel/track.rb Sat Jun 15 10:07:32 2013
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+# Rubyripper - A secure ripper for Linux/BSD/OSX
+# Copyright (C) 2013 Bouke Woudstra (boukew...@gmail.com)
+#
+# This file is part of Rubyripper. Rubyripper is free software: you can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+# This class stores all disc data
+module Datamodel
+ class Track
+ attr_accessor :number
+ attr_accessor :startSector
+ attr_accessor :lengthSector
+ end
+end
=======================================
--- /dev/null
+++ /lib/rubyripper/disc/ripStrategy.rb Sat Jun 15 10:07:32 2013
@@ -0,0 +1,57 @@
+#!/usr/bin/env ruby
+# Rubyripper - A secure ripper for Linux/BSD/OSX
+# Copyright (C) 2013 Bouke Woudstra (boukew...@gmail.com)
+#
+# This file is part of Rubyripper. Rubyripper is free software: you can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+require 'rubyripper/modules/audioCalculations'
+require 'rubyripper/datamodel/track'
+
+class RipStrategy
+ include AudioCalculations
+
+ # disc is the datamodel object
+ def initialize(disc, prefs=nil)
+ @disc = disc
+ @prefs = prefs ? prefs : Preferences::Main.instance()
+ end
+
+ def getTrack(number)
+ @disc.getTrack(number)
+ end
+
+ def isHiddenTrackAvailable
+ if @prefs.ripHiddenAudio
+ minimumSectors = @prefs.minLengthHiddenTrack * FRAMES_A_SECOND
+ return @disc.getTrack(1).startSector >= minimumSectors
+ else
+ return false
+ end
+ end
+
+ def getHiddenTrack
+ if isHiddenTrackAvailable
+ hiddenTrack = Datamodel::Track.new()
+ hiddenTrack.startSector = 0
+ hiddenTrack.lengthSector = @disc.getTrack(1).startSector
+ return hiddenTrack
+ else
+ raise "Only use this function if a hidden track is available: use
isHiddenTrackAvailable() first."
+ end
+ end
+
+ def getCdParanoiaSectorsToRipString(tracknumber)
+
return "#{@disc.getTrack(tracknumber).startSector}-#{@disc.getTrack(tracknumber).lengthSector}"
+ end
+end
=======================================
--- /dev/null
+++ /spec/disc/RipStrategy_spec.rb Sat Jun 15 10:07:32 2013
@@ -0,0 +1,70 @@
+require 'rubyripper/disc/ripStrategy'
+require 'rubyripper/datamodel/disc'
+
+describe RipStrategy do
+
+ let(:prefs) {double('Preferences').as_null_object}
+
+ context 'When no special attributes are there' do
+ it 'should be able to create a new instance' do
+ disc = Datamodel::Disc.new()
+ strategy = RipStrategy.new(disc, prefs)
+ strategy.class.should == RipStrategy
+ end
+
+ it 'should be able to show the cdparanoia parameters for a normal
1-track disc' do
+ disc = Datamodel::Disc.new()
+ disc.addTrack(number=1, startsector=0, lengthsector=1000)
+ strategy = RipStrategy.new(disc, prefs)
+ strategy.getTrack(1).startSector.should == 0
+ strategy.getTrack(1).lengthSector.should == 1000
+ end
+ end
+
+ context 'When hidden track info is available' do
+ it 'should be able to detect a hidden track when bigger than minimum
length preference' do
+ data = Datamodel::Disc.new()
+ data.addTrack(number=1, startsector=750, lengthsector=1000)
+ prefs.stub!('ripHiddenAudio').and_return true
+ prefs.stub!('minLengthHiddenTrack').and_return(0)
+ strategy = RipStrategy.new(data, prefs)
+ strategy.isHiddenTrackAvailable.should == true
+ track = strategy.getHiddenTrack()
+ track.startSector.should == 0
+ track.lengthSector.should == 750
+ end
+
+ # 10 seconds * 75 = 750 frames
+ it 'should be able to detect a hidden track when equal to minimum
length preference' do
+ data = Datamodel::Disc.new()
+ data.addTrack(number=1, startsector=750, lengthsector=1000)
+ prefs.stub!('ripHiddenAudio').and_return true
+ prefs.stub!('minLengthHiddenTrack').and_return(10)
+ strategy = RipStrategy.new(data, prefs)
+ strategy.isHiddenTrackAvailable.should == true
+ track = strategy.getHiddenTrack()
+ track.startSector.should == 0
+ track.lengthSector.should == 750
+ end
+
+ it 'should not detect a hidden track when smaller than minimum length
preference' do
+ data = Datamodel::Disc.new()
+ data.addTrack(number=1, startsector=750, lengthsector=1000)
+ prefs.stub!('ripHiddenAudio').and_return true
+ prefs.stub!('minLengthHiddenTrack').and_return(11)
+ strategy = RipStrategy.new(data, prefs)
+ strategy.isHiddenTrackAvailable.should == false
+ expect {strategy.getHiddenTrack}.to raise_error(RuntimeError)
+ end
+
+ it 'should ignore hidden track if ripHiddenAudio is disabled in
preferences' do
+ data = Datamodel::Disc.new()
+ data.addTrack(number=1, startsector=750, lengthsector=1000)
+ prefs.stub!('ripHiddenAudio').and_return false
+ prefs.stub!('minLengthHiddenTrack').and_return(0)
+ strategy = RipStrategy.new(data, prefs)
+ strategy.isHiddenTrackAvailable.should == false
+ expect {strategy.getHiddenTrack}.to raise_error(RuntimeError)
+ end
+ end
+end
Reply all
Reply to author
Forward
0 new messages