class RuboCop::Cop::Style::MagicCommentFormat::CommentRange

Value object to extract source ranges for the different parts of a magic comment

Constants

DIRECTIVE_REGEXP
VALUE_REGEXP

Attributes

comment[R]

Public Class Methods

new(comment) click to toggle source
# File lib/rubocop/cop/style/magic_comment_format.rb, line 119
def initialize(comment)
  @comment = comment
end

Public Instance Methods

directives() click to toggle source

A magic comment can contain one directive (normal style) or multiple directives (emacs style)

# File lib/rubocop/cop/style/magic_comment_format.rb, line 125
def directives
  @directives ||= begin
    matches = []

    text.scan(DIRECTIVE_REGEXP) do
      offset = Regexp.last_match.offset(0)
      matches << loc.expression.adjust(begin_pos: offset.first)
                    .with(end_pos: loc.expression.begin_pos + offset.last)
    end

    matches
  end
end
values() click to toggle source

A magic comment can contain one value (normal style) or multiple directives (emacs style)

# File lib/rubocop/cop/style/magic_comment_format.rb, line 141
def values
  @values ||= begin
    matches = []

    text.scan(VALUE_REGEXP) do
      offset = Regexp.last_match.offset(1)
      matches << loc.expression.adjust(begin_pos: offset.first)
                    .with(end_pos: loc.expression.begin_pos + offset.last)
    end

    matches
  end
end