OTWO-1213 Works around lost encoding in Ruby/C binding layer
[ohcount] / ruby / gestalt / rules / csproj_rule.rb
1 require 'rexml/document'
2 module Ohcount
3         module Gestalt
4                 class CsprojRule < FileRule
5
6                         attr_accessor :import
7
8                         def initialize(*args)
9                                 @import = args.shift || /.*/
10                                 @import = /^#{Regexp.escape(@import.to_s)}$/ unless @import.is_a? Regexp
11
12                                 super(args)
13                         end
14
15       def process_source_file(source_file)
16         if source_file.filename =~ /\.csproj$/ && source_file.language_breakdown('xml')
17                                         callback = lambda do |import|
18                                                 @count += 1 if import =~ @import
19                                         end
20
21                                         begin
22                 REXML::Document.parse_stream(source_file.language_breakdown('xml').code, CsprojListener.new(callback))
23                                         rescue REXML::ParseException
24                                                 # Malformed XML! -- ignore and move on
25                                         end
26         end
27       end
28
29                 end
30         end
31 end