Class: Uniword::Warnings::WarningCollector
- Inherits:
-
Object
- Object
- Uniword::Warnings::WarningCollector
- Defined in:
- lib/uniword/warnings/warning_collector.rb
Overview
Collects warnings during document processing.
Responsibility: Track unsupported elements and features. Single Responsibility: Only collects warnings.
This class is used during deserialization to track all unsupported elements and attributes encountered, allowing users to understand what features may be lost in round-trip operations.
External configuration: config/warning_rules.yml
Instance Attribute Summary collapse
-
#element_counts ⇒ Hash<String, Integer>
readonly
Element occurrence counts.
-
#warnings ⇒ Array<Warning>
readonly
Collected warnings.
Instance Method Summary collapse
-
#any? ⇒ Boolean
Check if warnings were collected.
-
#clear ⇒ void
Clear all collected warnings.
-
#initialize(config_file: nil) ⇒ WarningCollector
constructor
Initialize a new warning collector.
-
#record_unsupported(element_tag, context:, location: nil) ⇒ void
Record an unsupported element.
-
#record_unsupported_attribute(element_tag, attribute_name, context:) ⇒ void
Record an unsupported attribute.
-
#report ⇒ WarningReport
Generate warning report.
Constructor Details
#initialize(config_file: nil) ⇒ WarningCollector
Initialize a new warning collector.
39 40 41 42 43 |
# File 'lib/uniword/warnings/warning_collector.rb', line 39 def initialize(config_file: nil) @config = load_config(config_file) @warnings = [] @element_counts = Hash.new(0) end |
Instance Attribute Details
#element_counts ⇒ Hash<String, Integer> (readonly)
Returns Element occurrence counts.
26 27 28 |
# File 'lib/uniword/warnings/warning_collector.rb', line 26 def element_counts @element_counts end |
#warnings ⇒ Array<Warning> (readonly)
Returns Collected warnings.
23 24 25 |
# File 'lib/uniword/warnings/warning_collector.rb', line 23 def warnings @warnings end |
Instance Method Details
#any? ⇒ Boolean
Check if warnings were collected.
126 127 128 |
# File 'lib/uniword/warnings/warning_collector.rb', line 126 def any? @warnings.any? end |
#clear ⇒ void
This method returns an undefined value.
Clear all collected warnings.
133 134 135 136 |
# File 'lib/uniword/warnings/warning_collector.rb', line 133 def clear @warnings.clear @element_counts.clear end |
#record_unsupported(element_tag, context:, location: nil) ⇒ void
This method returns an undefined value.
Record an unsupported element.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/uniword/warnings/warning_collector.rb', line 58 def record_unsupported(element_tag, context:, location: nil) return unless enabled? return if max_warnings_reached? @element_counts[element_tag] += 1 warning = Warning.new( type: :unsupported_element, severity: determine_severity(element_tag), element: element_tag, message: "Unsupported element: #{element_tag}", context: context, location: location, suggestion: get_suggestion(element_tag), ) @warnings << warning log_warning(warning) if should_log? end |
#record_unsupported_attribute(element_tag, attribute_name, context:) ⇒ void
This method returns an undefined value.
Record an unsupported attribute.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/uniword/warnings/warning_collector.rb', line 91 def record_unsupported_attribute(element_tag, attribute_name, context:) return unless enabled? return if max_warnings_reached? warning = Warning.new( type: :unsupported_attribute, severity: :info, element: element_tag, attribute: attribute_name, message: "Unsupported attribute: #{element_tag}/@#{attribute_name}", context: context, ) @warnings << warning log_warning(warning) if should_log? end |
#report ⇒ WarningReport
Generate warning report.
115 116 117 118 119 120 121 |
# File 'lib/uniword/warnings/warning_collector.rb', line 115 def report WarningReport.new( warnings: @warnings, element_counts: @element_counts, config: @config, ) end |