Class: CommentExtractor::Extractor::Ruby

Inherits:
CommentExtractor::Extractor show all
Includes:
CodeObject::Comment::Type
Defined in:
lib/comment_extractor/extractor/ruby.rb

Defined Under Namespace

Classes: Options

Constant Summary

Constants included from CodeObject::Comment::Type

CodeObject::Comment::Type::BLOCK_COMMENT, CodeObject::Comment::Type::ONE_LINER_COMMENT

Constants inherited from CommentExtractor::Extractor

REGEXP, SCHAME_ACCESSOR_NAMES

Instance Attribute Summary

Attributes inherited from CommentExtractor::Extractor

#code_objects, #content

Instance Method Summary collapse

Methods inherited from CommentExtractor::Extractor

disable!, disabled?, #extract_comments, #initialize, schema, schema_accessor

Constructor Details

This class inherits a constructor from CommentExtractor::Extractor

Instance Method Details

#scanObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/comment_extractor/extractor/ruby.rb', line 17

def scan
  tokens = RDoc::RubyLex.tokenize(content, Options.new)

  tokens.each do |token|
    case token
    when RDoc::RubyToken::TkRD_COMMENT # =begin ... =end
      token.value.split("\n").each_with_index do |comment, index|
        line_no = token.line_no + 1 + index
        add_comment(line_no, comment, type: BLOCK_COMMENT)
      end
    when RDoc::RubyToken::TkCOMMENT # # ...
      comment = token.value.sub(/^\s*#\s?/, '')
      add_comment(token.line_no, comment, type: ONE_LINER_COMMENT)
    end
  end
end