class RuboCop::Cop::Badge
Identifier of all cops containing a department and cop name.
All cops are identified by their badge. For example, the badge for `RuboCop::Cop::Layout::Tab` is `Layout/Tab`. Badges can be parsed as either `Department/CopName` or just `CopName` to allow for badge references in source files that omit the department for RuboCop to infer.
Attributes
cop_name[R]
department[R]
Public Class Methods
for(class_name)
click to toggle source
# File lib/rubocop/cop/badge.rb, line 24 def self.for(class_name) new(*class_name.split('::').last(2)) end
new(department, cop_name)
click to toggle source
# File lib/rubocop/cop/badge.rb, line 40 def initialize(department, cop_name) @department = department.to_sym if department @cop_name = cop_name end
parse(identifier)
click to toggle source
# File lib/rubocop/cop/badge.rb, line 28 def self.parse(identifier) parts = identifier.split('/', 2) raise InvalidBadge, identifier if parts.size > 2 if parts.one? new(nil, *parts) else new(*parts) end end
Public Instance Methods
==(other)
click to toggle source
# File lib/rubocop/cop/badge.rb, line 45 def ==(other) hash == other.hash end
Also aliased as: eql?
hash()
click to toggle source
# File lib/rubocop/cop/badge.rb, line 50 def hash [department, cop_name].hash end
match?(other)
click to toggle source
# File lib/rubocop/cop/badge.rb, line 54 def match?(other) cop_name == other.cop_name && (!qualified? || department == other.department) end
qualified?()
click to toggle source
# File lib/rubocop/cop/badge.rb, line 63 def qualified? !department.nil? end
to_s()
click to toggle source
# File lib/rubocop/cop/badge.rb, line 59 def to_s qualified? ? "#{department}/#{cop_name}" : cop_name end
with_department(department)
click to toggle source
# File lib/rubocop/cop/badge.rb, line 67 def with_department(department) self.class.new(department, cop_name) end