123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::MagicComment::EditorComment Abstract

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, MagicComment
Instance Chain:
self, MagicComment
Inherits: MagicComment
  • Object
Defined in: lib/rubocop/magic_comment.rb

Overview

This class is abstract.

Parent to Vim and Emacs magic comment handling.

Instance Method Summary

Instance Method Details

#encoding

[ GitHub ]

  
# File 'lib/rubocop/magic_comment.rb', line 149

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

#match(keyword) ⇒ String? (private)

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

Parameters:

Returns:

  • (String)

    extracted value if it is found

  • (nil)

    otherwise

[ GitHub ]

  
# File 'lib/rubocop/magic_comment.rb', line 169

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

#tokensArray<String> (private)

Individual tokens composing an editor specific comment string.

[ GitHub ]

  
# File 'lib/rubocop/magic_comment.rb', line 184

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

#without(type)

Rewrite the comment without a given token type

[ GitHub ]

  
# File 'lib/rubocop/magic_comment.rb', line 154

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