more filter separation

This commit is contained in:
John Bintz 2010-01-04 22:55:50 -05:00
parent 2758239c1a
commit 8e16d7cc00
8 changed files with 110 additions and 76 deletions

4
Makefile Normal file
View File

@ -0,0 +1,4 @@
.PHONY : test
test :
testrb -b tests/*

View File

@ -1,7 +1,4 @@
require 'singleton'
class Filter
include Singleton
@config = {}
@cleanup = []

5
classes/InputFilter.rb Normal file
View File

@ -0,0 +1,5 @@
require 'filter'
class InputFilter < Filter
OutputFilename = "tmp.png"
end

17
classes/OutputFilter.rb Normal file
View File

@ -0,0 +1,17 @@
require File.dirname(__FILE__) + '/Filter.rb'
class OutputFilter < Filter
#
# get the output filename for this filter
#
def filename(info)
target = @config['target']
info.each { |k,v| target = target.gsub("{#{k}}", v.to_s) }
target
end
#
# get the output targets for this filter
#
def targets(info); filename(info); end
end

View File

@ -3,10 +3,8 @@
require 'yaml'
require 'time'
require File.dirname(__FILE__) + '/classes/Filter.rb'
class InputFilter < Filter
OutputFilename = "tmp.png"
Dir[File.dirname(__FILE__) + "/classes/*.rb"].each do |file|
require file
end
class OutputFilter < Filter

View File

@ -1,5 +1,3 @@
#!/usr/bin/ruby
require 'rubygems'
require 'test/unit'
require 'mockfs/override'

17
tests/TestOutputFilter.rb Normal file
View File

@ -0,0 +1,17 @@
require 'rubygems'
require 'test/unit'
require 'mocha'
require File.dirname(__FILE__) + '/../classes/OutputFilter.rb'
class TestOutputFilter < Test::Unit::TestCase
def setup
@of = OutputFilter.new
@of.stubs(:recalc_pixels)
end
def test_filename
@of.config = { 'target' => 'test{test}{test2}test3' }
assert_equal 'testtest4test5test3', @of.filename({ 'test' => 'test4', 'test2' => 'test5' })
end
end

View File

@ -1,5 +1,3 @@
#!/usr/bin/ruby
require 'rubygems'
require 'test/unit'
require File.dirname(__FILE__) + '/../classes/Scheduler.rb'