Class: FeatureMap::Private::TodoInspector
- Inherits:
-
Object
- Object
- FeatureMap::Private::TodoInspector
- Defined in:
- lib/feature_map/private/todo_inspector.rb
Constant Summary collapse
- ENTERING_COMMENT =
/ (#{(Constants::SINGLE_LINE_COMMENT_PATTERNS + Constants::MULTILINE_COMMENT_START_PATTERNS).join('|')}) /x.freeze
- EXITING_COMMENT =
/ (#{(Constants::SINGLE_LINE_COMMENT_PATTERNS + Constants::MULTILINE_COMMENT_END_PATTERNS).join('|')}) /x.freeze
- TODO_PATTERN =
/ TODO:?\s* # TODO with optional colon with whitespace (?<content>.*?) # The actual TODO content (#{Constants::MULTILINE_COMMENT_END_PATTERNS.join('|')})?$ # ignores comment end patterns /xi.freeze
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(file_path) ⇒ TodoInspector
constructor
A new instance of TodoInspector.
Constructor Details
#initialize(file_path) ⇒ TodoInspector
Returns a new instance of TodoInspector.
21 22 23 |
# File 'lib/feature_map/private/todo_inspector.rb', line 21 def initialize(file_path) @file_path = file_path end |
Instance Method Details
#calculate ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/feature_map/private/todo_inspector.rb', line 25 def calculate todos = {} content = File.read(@file_path) in_comment = false content.each_line.with_index do |line, index| in_comment ||= line.match?(ENTERING_COMMENT) if in_comment && (match = line.match(TODO_PATTERN)) todos["#{@file_path}:#{index + 1}"] = match[:content].strip end in_comment &&= !line.match?(EXITING_COMMENT) end todos end |