class RubbyCop::MagicComment::EditorComment

Parent to Vim and Emacs magic comment handling.

@abstract

Private Instance Methods

match(keyword) click to toggle source

Find a token starting with the provided keyword and extract its value.

@param keyword [String]

@return [String] extracted value if it is found @return [nil] otherwise

# File lib/rubbycop/magic_comment.rb, line 100
def match(keyword)
  pattern = /\A#{keyword}\s*#{self.class::OPERATOR}\s*(#{TOKEN})\z/

  tokens.each do |token|
    next unless (value = token[pattern, 1])

    return value.downcase
  end

  nil
end
tokens() click to toggle source

Individual tokens composing an editor specific comment string.

@return [Array<String>]

# File lib/rubbycop/magic_comment.rb, line 115
def tokens
  extract(self.class::FORMAT).split(self.class::SEPARATOR).map(&:strip)
end