Class: Markdown::Merge::DocumentProblems

Inherits:
Object
  • Object
show all
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.

Examples:

Basic usage

problems = DocumentProblems.new
problems.add(:duplicate_link_definition, label: "example", url: "https://example.com")
problems.add(:excessive_whitespace, line: 42, count: 5, severity: :warning)
problems.empty? # => false
problems.count # => 2

Filtering by category

problems.by_category(:duplicate_link_definition)
# => [{ category: :duplicate_link_definition, label: "example", ... }]

Filtering by severity

problems.by_severity(:error)
problems.warnings
problems.errors

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

Instance Method Summary collapse

Constructor Details

#initializeDocumentProblems

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

#problemsArray<Problem> (readonly)

Returns All collected problems.

Returns:

  • (Array<Problem>)

    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.

Parameters:

  • category (Symbol)

    Problem category (see CATEGORIES)

  • severity (Symbol) (defaults to: :warning)

    Severity level (:info, :warning, :error), default :warning

  • details (Hash)

    Additional details about the problem

Returns:



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

#allArray<Hash>

Get all problems as an array of hashes.

Returns:

  • (Array<Hash>)

    All problems



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.

Parameters:

  • category (Symbol)

    Category to filter by

Returns:

  • (Array<Problem>)

    Problems in that 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.

Parameters:

  • severity (Symbol)

    Severity to filter by

Returns:

  • (Array<Problem>)

    Problems with that severity



100
101
102
# File 'lib/markdown/merge/document_problems.rb', line 100

def by_severity(severity)
  @problems.select { |p| p.severity == severity }
end

#clearself

Clear all problems.

Returns:

  • (self)


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.

Parameters:

  • category (Symbol, nil) (defaults to: nil)

    Optional category filter

  • severity (Symbol, nil) (defaults to: nil)

    Optional severity filter

Returns:

  • (Integer)

    Problem count



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.

Returns:

  • (Boolean)

    true if no problems



128
129
130
# File 'lib/markdown/merge/document_problems.rb', line 128

def empty?
  @problems.empty?
end

#errorsArray<Problem>

Get all error-level problems.

Returns:

  • (Array<Problem>)

    Error problems



121
122
123
# File 'lib/markdown/merge/document_problems.rb', line 121

def errors
  by_severity(:error)
end

#infosArray<Problem>

Get all info-level problems.

Returns:

  • (Array<Problem>)

    Info 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.

Parameters:

Returns:

  • (self)


148
149
150
151
# File 'lib/markdown/merge/document_problems.rb', line 148

def merge!(other)
  @problems.concat(other.problems)
  self
end

#summary_by_categoryHash<Symbol, Integer>

Get a summary of problems by category.

Returns:

  • (Hash<Symbol, Integer>)

    Counts 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_severityHash<Symbol, Integer>

Get a summary of problems by severity.

Returns:

  • (Hash<Symbol, Integer>)

    Counts 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

#warningsArray<Problem>

Get all warning-level problems.

Returns:

  • (Array<Problem>)

    Warning problems



114
115
116
# File 'lib/markdown/merge/document_problems.rb', line 114

def warnings
  by_severity(:warning)
end