Class: Markdown::Merge::DocumentProblems
- Inherits:
-
Object
- Object
- Markdown::Merge::DocumentProblems
- Defined in:
- lib/markdown/merge/document_problems.rb
Overview
Container for document issues found during processing.
Collects problems discovered during merge operations, link reference rehydration, whitespace normalization, and other document transformations. Problems are categorized and have severity levels for filtering and reporting.
Defined Under Namespace
Classes: Problem
Constant Summary collapse
- SEVERITIES =
Valid severity levels
i[info warning error].freeze
- CATEGORIES =
Valid problem categories
i[ duplicate_link_definition excessive_whitespace link_has_title image_has_title link_ref_spacing ].freeze
Instance Attribute Summary collapse
-
#problems ⇒ Array<Problem>
readonly
All collected problems.
Instance Method Summary collapse
-
#add(category, severity: :warning, **details) ⇒ Problem
Add a problem to the collection.
-
#all ⇒ Array<Hash>
Get all problems as an array of hashes.
-
#by_category(category) ⇒ Array<Problem>
Get problems by category.
-
#by_severity(severity) ⇒ Array<Problem>
Get problems by severity.
-
#clear ⇒ self
Clear all problems.
-
#count(category: nil, severity: nil) ⇒ Integer
Get the count of problems.
-
#empty? ⇒ Boolean
Check if there are any problems.
-
#errors ⇒ Array<Problem>
Get all error-level problems.
-
#infos ⇒ Array<Problem>
Get all info-level problems.
-
#initialize ⇒ DocumentProblems
constructor
A new instance of DocumentProblems.
-
#merge!(other) ⇒ self
Merge another DocumentProblems into this one.
-
#summary_by_category ⇒ Hash<Symbol, Integer>
Get a summary of problems by category.
-
#summary_by_severity ⇒ Hash<Symbol, Integer>
Get a summary of problems by severity.
-
#warnings ⇒ Array<Problem>
Get all warning-level problems.
Constructor Details
#initialize ⇒ DocumentProblems
Returns a new instance of DocumentProblems.
62 63 64 |
# File 'lib/markdown/merge/document_problems.rb', line 62 def initialize @problems = [] end |
Instance Attribute Details
#problems ⇒ Array<Problem> (readonly)
Returns All collected problems.
60 61 62 |
# File 'lib/markdown/merge/document_problems.rb', line 60 def problems @problems end |
Instance Method Details
#add(category, severity: :warning, **details) ⇒ Problem
Add a problem to the collection.
72 73 74 75 76 77 78 79 |
# File 'lib/markdown/merge/document_problems.rb', line 72 def add(category, severity: :warning, **details) validate_category!(category) validate_severity!(severity) problem = Problem.new(category: category, severity: severity, details: details) @problems << problem problem end |
#all ⇒ Array<Hash>
Get all problems as an array of hashes.
84 85 86 |
# File 'lib/markdown/merge/document_problems.rb', line 84 def all @problems.map(&:to_h) end |
#by_category(category) ⇒ Array<Problem>
Get problems by category.
92 93 94 |
# File 'lib/markdown/merge/document_problems.rb', line 92 def by_category(category) @problems.select { |p| p.category == category } end |
#by_severity(severity) ⇒ Array<Problem>
Get problems by severity.
100 101 102 |
# File 'lib/markdown/merge/document_problems.rb', line 100 def by_severity(severity) @problems.select { |p| p.severity == severity } end |
#clear ⇒ self
Clear all problems.
156 157 158 159 |
# File 'lib/markdown/merge/document_problems.rb', line 156 def clear @problems.clear self end |
#count(category: nil, severity: nil) ⇒ Integer
Get the count of problems.
137 138 139 140 141 142 |
# File 'lib/markdown/merge/document_problems.rb', line 137 def count(category: nil, severity: nil) filtered = @problems filtered = filtered.select { |p| p.category == category } if category filtered = filtered.select { |p| p.severity == severity } if severity filtered.size end |
#empty? ⇒ Boolean
Check if there are any problems.
128 129 130 |
# File 'lib/markdown/merge/document_problems.rb', line 128 def empty? @problems.empty? end |
#errors ⇒ Array<Problem>
Get all error-level problems.
121 122 123 |
# File 'lib/markdown/merge/document_problems.rb', line 121 def errors by_severity(:error) end |
#infos ⇒ Array<Problem>
Get all info-level problems.
107 108 109 |
# File 'lib/markdown/merge/document_problems.rb', line 107 def infos by_severity(:info) end |
#merge!(other) ⇒ self
Merge another DocumentProblems into this one.
148 149 150 151 |
# File 'lib/markdown/merge/document_problems.rb', line 148 def merge!(other) @problems.concat(other.problems) self end |
#summary_by_category ⇒ Hash<Symbol, Integer>
Get a summary of problems by category.
164 165 166 |
# File 'lib/markdown/merge/document_problems.rb', line 164 def summary_by_category @problems.group_by(&:category).transform_values(&:size) end |
#summary_by_severity ⇒ Hash<Symbol, Integer>
Get a summary of problems by severity.
171 172 173 |
# File 'lib/markdown/merge/document_problems.rb', line 171 def summary_by_severity @problems.group_by(&:severity).transform_values(&:size) end |
#warnings ⇒ Array<Problem>
Get all warning-level problems.
114 115 116 |
# File 'lib/markdown/merge/document_problems.rb', line 114 def warnings by_severity(:warning) end |