class RuboCop::MagicComment::EditorComment
Parent to Vim and Emacs magic comment handling.
@abstract
Public Instance Methods
encoding()
click to toggle source
# File lib/rubocop/magic_comment.rb, line 139 def encoding match(self.class::KEYWORDS[:encoding]) end
without(type)
click to toggle source
Rewrite the comment without a given token type
# File lib/rubocop/magic_comment.rb, line 144 def without(type) remaining = tokens.grep_v(/\A#{self.class::KEYWORDS[type.to_sym]}/) return '' if remaining.empty? self.class::FORMAT % remaining.join(self.class::SEPARATOR) end
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/rubocop/magic_comment.rb, line 159 def match(keyword) pattern = /\A#{keyword}\s*#{self.class::OPERATOR}\s*#{TOKEN}\z/ tokens.each do |token| next unless (value = token[pattern, :token]) return value.downcase end nil end
tokens()
click to toggle source
Individual tokens composing an editor specific comment string.
@return [Array<String>]
# File lib/rubocop/magic_comment.rb, line 174 def tokens extract(self.class::REGEXP).split(self.class::SEPARATOR).map(&:strip) end