public
Description: Augment is a system for gathering metadata from code and displaying it.
Homepage: http://augment.rubyforge.org
Clone URL: git://github.com/technomancy/augment.git
augment / lib / backends / color_backend.rb
100644 30 lines (24 sloc) 0.727 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
##
# This backend is just a dummy that isn't actually useful for anything
# other than testing purposes.
#
class ColoringBackend < Backend
  COLORS = ['white', 'red', 'green', 'blue', 'black']
  
  class << self
    attr_reader :layers
    
    def run(file)
      @layers = Hash.new { |h,k| h[k] = [] }
      text = File.read(file)
 
      COLORS.each do |color|
        offset = 0
        while occurance = text.index(color, offset) do
          @layers[file] << Layer.new((occurance ... occurance + color.length),
                                     color, "Found a #{color}", self)
          offset += (occurance + 1)
        end
      end
      
      write_layers
    end
  end
  
  Augment::BACKENDS['color'] = self
end