class RuboCop::MagicComment::EditorComment

@abstract
Parent to Vim and Emacs magic comment handling.

def encoding

def encoding
  match(self.class::KEYWORDS[:encoding])
end

def match(keyword)

Returns:
  • (nil) - otherwise
  • (String) - extracted value if it is found

Parameters:
  • keyword (String) --
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

def tokens

Returns:
  • (Array) -
def tokens
  extract(self.class::REGEXP).split(self.class::SEPARATOR).map(&:strip)
end

def without(type)

Rewrite the comment without a given token type
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