Class: ArtPaintingsExtractor::ArtPaintings

Inherits:
Object
  • Object
show all
Defined in:
lib/art_paintings.rb

Overview

This class is responsible for extracting painting information from an HTML file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html_file) ⇒ ArtPaintings

Returns a new instance of ArtPaintings.



15
16
17
18
# File 'lib/art_paintings.rb', line 15

def initialize(html_file)
  @logger = Logger.new($stdout)
  @doc = HtmlDocument.new(html_file).call
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



13
14
15
# File 'lib/art_paintings.rb', line 13

def doc
  @doc
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/art_paintings.rb', line 13

def logger
  @logger
end

Instance Method Details

#build_painting_info(item) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/art_paintings.rb', line 28

def build_painting_info(item)
  info = {
    'name' => extract_name(item),
    'link' => extract_link(item),
    'image' => nil
    # 'image' => extract_image(item)
  }

  extensions = extract_extensions(item)
  info['extensions'] = [extensions] unless extensions.empty?

  info
end

#extract_paintingsObject



24
25
26
# File 'lib/art_paintings.rb', line 24

def extract_paintings
  paintings.map { |item| build_painting_info(item) }
end

#paintingsObject



20
21
22
# File 'lib/art_paintings.rb', line 20

def paintings
  @doc.css('.klitem')
end