Class: Obp::Access::Imager

Inherits:
Object
  • Object
show all
Defined in:
lib/obp/access/imager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html:, directory:) ⇒ Imager

Returns a new instance of Imager.



6
7
8
9
# File 'lib/obp/access/imager.rb', line 6

def initialize(html:, directory:)
  @html = html
  @directory = directory
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



4
5
6
# File 'lib/obp/access/imager.rb', line 4

def directory
  @directory
end

#htmlObject (readonly)

Returns the value of attribute html.



4
5
6
# File 'lib/obp/access/imager.rb', line 4

def html
  @html
end

Instance Method Details

#imagesObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/obp/access/imager.rb', line 11

def images
  doc = Nokogiri::HTML(html)
  images = doc.search("div.sts-fig > img").to_h do |img|
    key = img.attr("src")
    path = File.join(imgdir, key.split("/").last)
    [key, path]
  end
  download_images(images)
  images
end