Module: Metado::Parser::File

Defined in:
lib/metado/parser/file.rb

Class Method Summary collapse

Class Method Details

.comments(file) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/metado/parser/file.rb', line 7

def comments file
  regex = single_line_comment_regex(file)

  ::File.readlines(file).each_with_index.reduce([[], nil]) { |(comments, current_comment), (line, index)|
    if (line = line[regex, 1])
      (current_comment ||= Type::Comment.new(file, index + 1, []).tap(&comments.method(:push))).body << line
    else
      current_comment = nil
    end

    [comments, current_comment]
  }.first
end