Class: Uniword::Warnings::WarningReport
- Inherits:
-
Object
- Object
- Uniword::Warnings::WarningReport
- Defined in:
- lib/uniword/warnings/warning_report.rb
Overview
Aggregated warning report.
Responsibility: Aggregate and report warnings. Single Responsibility: Only manages warning reporting.
A warning report includes:
-
Collection of all warnings
-
Element occurrence counts
-
Grouping by severity
-
Summary statistics
Instance Attribute Summary collapse
-
#element_counts ⇒ Hash<String, Integer>
readonly
Element occurrence counts.
-
#warnings ⇒ Array<Warning>
readonly
All warnings.
Instance Method Summary collapse
-
#any? ⇒ Boolean
Check if report has any warnings.
-
#error_count ⇒ Integer
Get count of error warnings.
-
#errors ⇒ Array<Warning>
Get error-level warnings.
-
#info_count ⇒ Integer
Get count of info warnings.
-
#infos ⇒ Array<Warning>
Get info-level warnings.
-
#initialize(warnings:, element_counts:, config: {}) ⇒ WarningReport
constructor
Initialize a new warning report.
-
#summary ⇒ String
Generate summary text.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_json(*_args) ⇒ String
Export to JSON string.
-
#to_s ⇒ String
Convert to string for display.
-
#total_count ⇒ Integer
Get total warning count.
-
#warning_count ⇒ Integer
Get count of warning-level warnings.
-
#warnings_only ⇒ Array<Warning>
Get warning-level warnings.
Constructor Details
#initialize(warnings:, element_counts:, config: {}) ⇒ WarningReport
Initialize a new warning report.
42 43 44 45 46 |
# File 'lib/uniword/warnings/warning_report.rb', line 42 def initialize(warnings:, element_counts:, config: {}) @warnings = warnings @element_counts = element_counts @config = config end |
Instance Attribute Details
#element_counts ⇒ Hash<String, Integer> (readonly)
Returns Element occurrence counts.
29 30 31 |
# File 'lib/uniword/warnings/warning_report.rb', line 29 def element_counts @element_counts end |
#warnings ⇒ Array<Warning> (readonly)
Returns All warnings.
26 27 28 |
# File 'lib/uniword/warnings/warning_report.rb', line 26 def warnings @warnings end |
Instance Method Details
#any? ⇒ Boolean
Check if report has any warnings.
51 52 53 |
# File 'lib/uniword/warnings/warning_report.rb', line 51 def any? @warnings.any? end |
#error_count ⇒ Integer
Get count of error warnings.
79 80 81 |
# File 'lib/uniword/warnings/warning_report.rb', line 79 def error_count errors.count end |
#errors ⇒ Array<Warning>
Get error-level warnings.
58 59 60 |
# File 'lib/uniword/warnings/warning_report.rb', line 58 def errors @warnings.select(&:error?) end |
#info_count ⇒ Integer
Get count of info warnings.
93 94 95 |
# File 'lib/uniword/warnings/warning_report.rb', line 93 def info_count infos.count end |
#infos ⇒ Array<Warning>
Get info-level warnings.
72 73 74 |
# File 'lib/uniword/warnings/warning_report.rb', line 72 def infos @warnings.select(&:info?) end |
#summary ⇒ String
Generate summary text.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/uniword/warnings/warning_report.rb', line 107 def summary return "No warnings" unless any? lines = [] lines << "Found #{total_count} warning(s):" lines << " Errors: #{error_count}" lines << " Warnings: #{warning_count}" lines << " Info: #{info_count}" if @element_counts.any? lines << "" lines << "Unsupported elements encountered:" @element_counts.sort_by { |_, count| -count }.each do |element, count| lines << " #{element}: #{count} occurrence(s)" end end lines.join("\n") end |
#to_h ⇒ Hash
Convert to hash representation.
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/uniword/warnings/warning_report.rb', line 138 def to_h { total: total_count, by_severity: { errors: error_count, warnings: warning_count, infos: info_count, }, element_counts: @element_counts, warnings: @warnings.map(&:to_h), } end |
#to_json(*_args) ⇒ String
Export to JSON string.
131 132 133 |
# File 'lib/uniword/warnings/warning_report.rb', line 131 def to_json(*_args) JSON.pretty_generate(to_h) end |
#to_s ⇒ String
Convert to string for display.
154 155 156 |
# File 'lib/uniword/warnings/warning_report.rb', line 154 def to_s summary end |
#total_count ⇒ Integer
Get total warning count.
100 101 102 |
# File 'lib/uniword/warnings/warning_report.rb', line 100 def total_count @warnings.count end |
#warning_count ⇒ Integer
Get count of warning-level warnings.
86 87 88 |
# File 'lib/uniword/warnings/warning_report.rb', line 86 def warning_count warnings_only.count end |
#warnings_only ⇒ Array<Warning>
Get warning-level warnings.
65 66 67 |
# File 'lib/uniword/warnings/warning_report.rb', line 65 def warnings_only @warnings.select(&:warning?) end |