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::IndentationStyle` is `Layout/IndentationStyle`. 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

camel_case(name_part) click to toggle source
# File lib/rubocop/cop/badge.rb, line 25
def self.camel_case(name_part)
  return 'RSpec' if name_part == 'rspec'

  name_part.gsub(/^\w|_\w/) { |match| match[-1, 1].upcase }
end
for(class_name) click to toggle source
# File lib/rubocop/cop/badge.rb, line 15
def self.for(class_name)
  parts = class_name.split('::')
  name_deep_enough = parts.length >= 4
  new(name_deep_enough ? parts[2..] : parts.last(2))
end
new(class_name_parts) click to toggle source
# File lib/rubocop/cop/badge.rb, line 31
def initialize(class_name_parts)
  department_parts = class_name_parts[0...-1]
  @department = (department_parts.join('/').to_sym unless department_parts.empty?)
  @cop_name = class_name_parts.last
end
parse(identifier) click to toggle source
# File lib/rubocop/cop/badge.rb, line 21
def self.parse(identifier)
  new(identifier.split('/').map { |i| camel_case(i) })
end

Public Instance Methods

==(other) click to toggle source
# File lib/rubocop/cop/badge.rb, line 37
def ==(other)
  hash == other.hash
end
Also aliased as: eql?
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/rubocop/cop/badge.rb, line 42
def hash
  [department, cop_name].hash
end
match?(other) click to toggle source
# File lib/rubocop/cop/badge.rb, line 46
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 54
def qualified?
  !department.nil?
end
to_s() click to toggle source
# File lib/rubocop/cop/badge.rb, line 50
def to_s
  @to_s ||= qualified? ? "#{department}/#{cop_name}" : cop_name
end
with_department(department) click to toggle source
# File lib/rubocop/cop/badge.rb, line 58
def with_department(department)
  self.class.new([department.to_s.split('/'), cop_name].flatten)
end