Class: Glossarist::Validation::Rules::OrphanedImagesRule
- Defined in:
- lib/glossarist/validation/rules/orphaned_images_rule.rb
Instance Method Summary collapse
- #applicable?(context) ⇒ Boolean
- #category ⇒ Object
- #check(context) ⇒ Object
- #code ⇒ Object
- #scope ⇒ Object
- #severity ⇒ Object
Methods inherited from Base
Instance Method Details
#applicable?(context) ⇒ Boolean
12 13 14 |
# File 'lib/glossarist/validation/rules/orphaned_images_rule.rb', line 12 def applicable?(context) context.asset_index.paths.any? end |
#category ⇒ Object
8 |
# File 'lib/glossarist/validation/rules/orphaned_images_rule.rb', line 8 def category = :references |
#check(context) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/glossarist/validation/rules/orphaned_images_rule.rb', line 16 def check(context) extractor = ReferenceExtractor.new referenced_paths = Set.new context.concepts.each do |concept| concept.localizations.each do |l10n| l10n.text_content.each do |text| next unless text extractor.extract_from_text(text).each do |ref| if ref.is_a?(AssetReference) referenced_paths.add(ref.path) end end end end extractor.extract_asset_refs_from_concept(concept).each do |ref| referenced_paths.add(ref.path) end end images_file = load_images_file(context) if images_file context.bibliography_index.entries.each_value do |entry| next unless entry[:source].is_a?(V3::ImageEntry) path = entry[:source].path referenced_paths.add(path) if path end end issues = [] context.asset_index.each_path do |path| next if referenced_paths.include?(path) issues << issue( "Orphaned image: #{path} (not referenced by any concept)", code: code, severity: severity, location: path, suggestion: "Remove the image or reference it from a concept", ) end issues end |
#code ⇒ Object
7 |
# File 'lib/glossarist/validation/rules/orphaned_images_rule.rb', line 7 def code = "GLS-021" |
#scope ⇒ Object
10 |
# File 'lib/glossarist/validation/rules/orphaned_images_rule.rb', line 10 def scope = :collection |
#severity ⇒ Object
9 |
# File 'lib/glossarist/validation/rules/orphaned_images_rule.rb', line 9 def severity = "warning" |