Class: Debtective::Comments::BuildComment

Inherits:
Object
  • Object
show all
Defined in:
lib/debtective/comments/build_comment.rb

Overview

Build proper comment type given the code line

Constant Summary collapse

TYPES =

Order matters, for example the Comment::Note regex matches (almost) all previous regexes so it needs to be tested last

{
  /#\sTODO:/ => Comment::Todo,
  /#\sFIXME:/ => Comment::Fixme,
  /\s# rubocop:disable (.*)/ => Comment::Offense,
  /#\s@/ => Comment::Yard,
  /^# (frozen_string_literal|coding|encoding|warn_indent|sharable_constant_value):/ => Comment::Magic,
  /^#!/ => Comment::Shebang,
  /(^|\s)#\s/ => Comment::Note
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(line:, pathname:, index:) ⇒ BuildComment

Returns a new instance of BuildComment.

Parameters:

  • line (String)

    code line

  • pathname (Pathname)

    file path

  • index (Integer)

    position of the line in the file



30
31
32
33
34
# File 'lib/debtective/comments/build_comment.rb', line 30

def initialize(line:, pathname:, index:)
  @line = line
  @pathname = pathname
  @index = index
end

Instance Method Details

#callDebtective::Comments::Base

Returns:

  • (Debtective::Comments::Base)


37
38
39
# File 'lib/debtective/comments/build_comment.rb', line 37

def call
  klass&.new(pathname: @pathname, index: @index)
end