Class: LinkThumbnailer::Scraper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/link_thumbnailer/scraper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, url) ⇒ Scraper

Returns a new instance of Scraper.



23
24
25
26
27
28
29
30
31
32
# File 'lib/link_thumbnailer/scraper.rb', line 23

def initialize(source, url)
  @source       = source
  @url          = url
  @config       = ::LinkThumbnailer.page.config
  @document     = parser.call(source)
  @website      = ::LinkThumbnailer::Models::Website.new
  @website.url  = url

  super(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



21
22
23
# File 'lib/link_thumbnailer/scraper.rb', line 21

def config
  @config
end

#documentObject (readonly)

Returns the value of attribute document.



21
22
23
# File 'lib/link_thumbnailer/scraper.rb', line 21

def document
  @document
end

#sourceObject (readonly)

Returns the value of attribute source.



21
22
23
# File 'lib/link_thumbnailer/scraper.rb', line 21

def source
  @source
end

#urlObject (readonly)

Returns the value of attribute url.



21
22
23
# File 'lib/link_thumbnailer/scraper.rb', line 21

def url
  @url
end

#websiteObject (readonly)

Returns the value of attribute website.



21
22
23
# File 'lib/link_thumbnailer/scraper.rb', line 21

def website
  @website
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/link_thumbnailer/scraper.rb', line 34

def call
  config.attributes.each do |name|
    config.scrapers.each do |scraper_prefix|
      scraper_class(scraper_prefix, name).new(document, website).call(name.to_s)
      break unless website.send(name).blank?
    end
  end

  website
end