Added gestalts.
[ohcount] / ruby / gestalt / rules / filename_rule.rb
1 module Ohcount
2         module Gestalt
3                 # rule based a the name of the file
4                 class FilenameRule < FileRule
5                         attr_reader :filenames
6
7                         def initialize(*args)
8                                 options = args.pop if args.last.is_a?(Hash)
9                                 @filenames = args
10                                 super(options)
11                         end
12
13                         def process_source_file(source_file)
14                                 @count += 1 if regex.match(source_file.filename)
15                         end
16
17                         def regex
18                                 @regex ||= begin
19                                         r = filenames.collect { |f| "(" + f + ")"}.join("|")
20                                         Regexp.new(r)
21                                 end
22                         end
23                 end
24         end
25 end