module HeaderDetector
Public Class Methods
detect(path, template, comment_tokens)
click to toggle source
# 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