Class: Uniword::Batch::ValidateLinksStage
- Inherits:
-
ProcessingStage
- Object
- ProcessingStage
- Uniword::Batch::ValidateLinksStage
- Defined in:
- lib/uniword/batch/stages/validate_links_stage.rb
Overview
Processing stage that validates document links.
Responsibility: Check and report broken internal and external links. Single Responsibility - only handles link validation.
Instance Attribute Summary
Attributes inherited from ProcessingStage
Instance Method Summary collapse
-
#description ⇒ String
Get stage description.
-
#initialize(options = {}) ⇒ ValidateLinksStage
constructor
Initialize validate links stage.
-
#process(document, context = {}) ⇒ Document
Process document to validate links.
Methods inherited from ProcessingStage
Constructor Details
#initialize(options = {}) ⇒ ValidateLinksStage
Initialize validate links stage
26 27 28 29 30 31 32 33 |
# File 'lib/uniword/batch/stages/validate_links_stage.rb', line 26 def initialize( = {}) super @check_internal = .fetch(:check_internal, true) @check_external = .fetch(:check_external, false) @check_bookmarks = .fetch(:check_bookmarks, true) @report_broken = .fetch(:report_broken, true) @broken_link_action = .fetch(:broken_link_action, "report") end |
Instance Method Details
#description ⇒ String
Get stage description
74 75 76 |
# File 'lib/uniword/batch/stages/validate_links_stage.rb', line 74 def description "Validate document links" end |
#process(document, context = {}) ⇒ Document
Process document to validate links
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/uniword/batch/stages/validate_links_stage.rb', line 40 def process(document, context = {}) log "Validating links in #{context[:filename]}" broken_links = [] # Collect all hyperlinks hyperlinks = collect_hyperlinks(document) # Validate each hyperlink hyperlinks.each do |link| next unless should_validate_link?(link) if link_is_broken?(link, document) broken_links << link handle_broken_link(link, document) end end # Report results if @report_broken && broken_links.any? log "Found #{broken_links.size} broken link(s)", level: :warn broken_links.each do |link| log " - #{link[:type]}: #{link[:target]}", level: :warn end else log "All links valid" end document end |