class SleepingKingStudios::Tasks::Ci::RuboCopResults

Encapsulates the results of a RuboCop call.

Public Class Methods

new(results) click to toggle source

@param results [Hash] The raw results of the RuboCop call.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 9
def initialize results
  @results = results
end

Public Instance Methods

==(other) click to toggle source

@param other [RSpecResults] The other results object to compare.

@return [Boolean] True if the results are equal, otherwise false.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 16
def == other
  if other.is_a?(Hash)
    empty? ? other.empty? : to_h == other
  elsif other.is_a?(RuboCopResults)
    to_h == other.to_h
  else
    false
  end # if-elsif-else
end
empty?() click to toggle source

@return [Boolean] True if there are no inspected files, otherwise false.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 27
def empty?
  inspected_file_count.zero?
end
failing?() click to toggle source

@return [Boolean] True if there are any offenses, otherwise false.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 32
def failing?
  !offense_count.zero?
end
inspected_file_count() click to toggle source

@return [Integer] The number of inspected files.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 37
def inspected_file_count
  @results.fetch('inspected_file_count', 0)
end
merge(other) click to toggle source

Adds the given result values and returns a new results object with the sums.

@param other [RuboCopResults] The results to add.

@return [RuboCopResults] The total results.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 47
def merge other
  self.class.new(
    'inspected_file_count' =>
      inspected_file_count + other.inspected_file_count,
    'offense_count'        => offense_count + other.offense_count
  ) # end new
end
offense_count() click to toggle source

@return [Integer] The number of detected offenses.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 56
def offense_count
  @results.fetch('offense_count', 0)
end
pending?() click to toggle source

@return [Boolean] False.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 61
def pending?
  false
end
to_h() click to toggle source

@return [Hash] The hash representation of the results.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 66
def to_h
  {
    'inspected_file_count' => inspected_file_count,
    'offense_count'        => offense_count
  } # end hash
end
to_s() click to toggle source

@return [String] The string representation of the results.

# File lib/sleeping_king_studios/tasks/ci/rubocop_results.rb, line 74
def to_s
  str = "#{inspected_file_count} files inspected"

  str << ", #{offense_count} offenses"
end