Module: HeaderDetector

Defined in:
lib/header_detector.rb

Class Method Summary collapse

Class Method Details

.detect(path, template, comment_tokens) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/header_detector.rb', line 22

def HeaderDetector.detect(path, template, comment_tokens)
	template_lines = Comment.comment(template, comment_tokens).lines("\n")
	template_regexp_lines = template_lines.map do |line|
		TemplateUtils.create_detection_regexp_for_line(line)
	end
	potential_header_start = 0
	matches = []
	File.open(path, "r").each do |line|
		match = template_regexp_lines[matches.length].match(line)
		if match
			matches << match
			if matches.length == template_regexp_lines.length
				return {
					start: potential_header_start,
					matches: matches
				}
			end
		else
			potential_header_start += matches.length + 1
			matches = []
		end
	end
	nil
end