2014-06-27 18:39:39 -04:00
|
|
|
class WarningsSpy
|
|
|
|
class Reader
|
|
|
|
attr_reader :warning_groups
|
|
|
|
|
|
|
|
def initialize(filesystem)
|
|
|
|
@warnings_file = filesystem.warnings_file
|
|
|
|
|
|
|
|
@current_group = []
|
|
|
|
@warning_groups = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def read
|
|
|
|
warnings_file.rewind
|
|
|
|
|
|
|
|
warnings_file.each_line do |line|
|
|
|
|
process_line(line)
|
|
|
|
end
|
|
|
|
|
|
|
|
add_group(current_group)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
attr_reader :warnings_file, :current_group
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def process_line(line)
|
2014-11-20 14:03:37 -05:00
|
|
|
if start_of_group?(line)
|
|
|
|
add_group(current_group)
|
|
|
|
current_group.clear
|
2014-10-03 00:50:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
current_group << line
|
|
|
|
end
|
2014-06-27 18:39:39 -04:00
|
|
|
|
2014-11-20 14:03:37 -05:00
|
|
|
def start_of_group?(line)
|
|
|
|
line =~ /^\W/
|
2014-10-03 00:50:18 -04:00
|
|
|
end
|
|
|
|
|
2014-06-27 18:39:39 -04:00
|
|
|
def add_group(group)
|
2014-10-03 00:50:18 -04:00
|
|
|
unless group.empty? || group_already_added?(group)
|
2014-06-27 18:39:39 -04:00
|
|
|
warning_groups << group
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_already_added?(group_to_be_added)
|
|
|
|
warning_groups.any? do |group|
|
|
|
|
group == group_to_be_added
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|