Class: CommentExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/tom_extract/comment_extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(pathname, line_number) ⇒ CommentExtractor

Returns a new instance of CommentExtractor.



3
4
5
# File 'lib/tom_extract/comment_extractor.rb', line 3

def initialize(pathname, line_number)
  @pathname, @line_number = pathname, line_number
end

Instance Method Details

#commentObject



7
8
9
10
11
12
13
14
# File 'lib/tom_extract/comment_extractor.rb', line 7

def comment
  c = []
  source[0..(line_number-2)].reverse.each do |l|
    break if l.gsub(/\s/,'').empty?
    c << l if l.match(/\A\s*\#/)
  end
  c.reverse.join("\n")
end