updated to work with miniunit 1.1.0
[augment.git] / lib / backends / coloring_backend.rb
blob2632065099f71cf7ad6f582eca8dcacaa639c874
1 ##
2 # This backend is just a dummy that isn't actually useful for anything
3 # other than testing purposes.
5 class ColoringBackend < Backend
6   COLORS = ['white', 'red', 'green', 'blue', 'black']
7   
8   class << self
9     attr_reader :layers
10     
11     def run(file)
12       @layers = {}
13       text = File.read(file)
15       COLORS.each do |color|
16         offset = 0
17         while occurance = text.index(color, offset) do
18           (@layers[file] ||= []) << Layer.new((occurance ... occurance + color.length),
19                                               color, "Found a #{color}", self)
20           offset += (occurance + 1)
21         end
22       end
23       
24       write_layers
25     end
26   end
27   
28   Augment::BACKENDS['color'] = self
29 end