Class: Basilisk::ImageProcessor

Inherits:
CSVProcessor show all
Defined in:
lib/basilisk/processors/image_processor.rb

Overview

Generates a report for broken images and images missing alt tags.

Instance Method Summary collapse

Methods inherited from CSVProcessor

#write_file

Methods inherited from Processor

#close_file

Constructor Details

#initialize(search_name) ⇒ ImageProcessor

Returns a new instance of ImageProcessor.



8
9
10
11
12
# File 'lib/basilisk/processors/image_processor.rb', line 8

def initialize(search_name)
  super
  save_header_row
  @image_url_cache = []
end

Instance Method Details

#process_page(page, page_hash) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/basilisk/processors/image_processor.rb', line 14

def process_page(page, page_hash)
  return unless page.doc
  begin
    page.doc.css('img').each do |image|
      begin
      image_src = image['src']
      absolute_image_url = image_url(page, image_src)
      next if @image_url_cache.include?(absolute_image_url)
      @image_url_cache << absolute_image_url

      check_for_broken_image(page, absolute_image_url)
      check_for_missing_alt_tag(page, image, absolute_image_url)

    rescue BasiliskImageError => e
      write_row(page, image['src'], e.message)
    end
  end
  end
end