Class: SleepingKingStudios::Tasks::Ci::EslintResults
- Inherits:
-
Object
- Object
- SleepingKingStudios::Tasks::Ci::EslintResults
- Defined in:
- lib/sleeping_king_studios/tasks/ci/eslint_results.rb
Overview
Encapsulates the results of an Eslint call.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if the results are equal, otherwise false.
-
#empty? ⇒ Boolean
True if there are no inspected files, otherwise false.
-
#error_count ⇒ Integer
The total number of error results across all files.
-
#failing? ⇒ Boolean
True if there are no errors or warnings, otherwise false.
-
#initialize(results) ⇒ EslintResults
constructor
A new instance of EslintResults.
-
#inspected_file_count ⇒ Integer
The number of inspected files.
-
#pending? ⇒ Boolean
Always false.
-
#to_h ⇒ Hash
The hash representation of the results.
-
#to_s ⇒ String
The string representation of the results.
-
#warning_count ⇒ Integer
The total number of warning results across all files.
Constructor Details
#initialize(results) ⇒ EslintResults
Returns a new instance of EslintResults.
9 10 11 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 9 def initialize results @results = results end |
Instance Method Details
#==(other) ⇒ Boolean
Returns True if the results are equal, otherwise false.
16 17 18 19 20 21 22 23 24 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 16 def == other if other.is_a?(Array) empty? ? other.empty? : @results == other elsif other.is_a?(EslintResults) to_h == other.to_h else false end end |
#empty? ⇒ Boolean
Returns True if there are no inspected files, otherwise false.
27 28 29 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 27 def empty? inspected_file_count.zero? end |
#error_count ⇒ Integer
Returns The total number of error results across all files.
32 33 34 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 32 def error_count @error_count ||= @results.map { |hsh| hsh['errorCount'] }.sum end |
#failing? ⇒ Boolean
Returns True if there are no errors or warnings, otherwise false.
38 39 40 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 38 def failing? !(error_count.zero? && warning_count.zero?) end |
#inspected_file_count ⇒ Integer
Returns The number of inspected files.
43 44 45 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 43 def inspected_file_count @results.size end |
#pending? ⇒ Boolean
Returns Always false. Both warnings and errors trigger a failure state.
49 50 51 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 49 def pending? false end |
#to_h ⇒ Hash
Returns The hash representation of the results.
54 55 56 57 58 59 60 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 54 def to_h { 'inspected_file_count' => inspected_file_count, 'error_count' => error_count, 'warning_count' => warning_count } end |
#to_s ⇒ String
Returns The string representation of the results.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 63 def to_s # rubocop:disable Metrics/AbcSize str = +"#{pluralize inspected_file_count, 'file'} inspected" str << ", #{pluralize error_count, 'error'}" str << ", #{pluralize warning_count, 'warning'}" str << "\n" unless non_empty_results.empty? non_empty_results.each do |hsh| str << "\n #{format_result_item(hsh)}" end str end |
#warning_count ⇒ Integer
Returns The total number of warning results across all files.
80 81 82 |
# File 'lib/sleeping_king_studios/tasks/ci/eslint_results.rb', line 80 def warning_count @warning_count ||= @results.map { |hsh| hsh['warningCount'] }.sum end |