Class: Rubycli::Documentation::CommentExtractor
- Inherits:
-
Object
- Object
- Rubycli::Documentation::CommentExtractor
- Defined in:
- lib/rubycli/documentation/comment_extractor.rb
Overview
Extracts contiguous comment blocks that appear immediately before a method.
Instance Method Summary collapse
- #extract(file, line_number) ⇒ Object
-
#initialize ⇒ CommentExtractor
constructor
A new instance of CommentExtractor.
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ CommentExtractor
Returns a new instance of CommentExtractor.
7 8 9 |
# File 'lib/rubycli/documentation/comment_extractor.rb', line 7 def initialize @file_cache = {} end |
Instance Method Details
#extract(file, line_number) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubycli/documentation/comment_extractor.rb', line 11 def extract(file, line_number) return [] unless file && line_number lines = cached_lines_for(file) index = line_number - 2 block = [] while index >= 0 line = lines[index] break unless comment_line?(line) block << line index -= 1 end block.reverse.map { |line| strip_comment_prefix(line) } rescue Errno::ENOENT [] end |
#reset! ⇒ Object
31 32 33 |
# File 'lib/rubycli/documentation/comment_extractor.rb', line 31 def reset! @file_cache.clear end |