Class: DoctorScrape::Scraper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/doctor_scrape/scraper/base.rb

Direct Known Subclasses

Bora, Duo, Meta, Unknown

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/doctor_scrape/scraper/base.rb', line 7

def initialize(url)
  @url   = url
  @data  = DoctorScrape::Data.new url: @url
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/doctor_scrape/scraper/base.rb', line 5

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/doctor_scrape/scraper/base.rb', line 5

def errors
  @errors
end

Instance Method Details

#docObject



25
26
27
# File 'lib/doctor_scrape/scraper/base.rb', line 25

def doc
  @doc ||= Nokogiri::HTML @body
end

#errors?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/doctor_scrape/scraper/base.rb', line 33

def errors?
  errors.any?
end

#fetchObject



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

def fetch
  @body ||= open(url)
end

#scrapeObject



12
13
14
15
16
17
18
19
# File 'lib/doctor_scrape/scraper/base.rb', line 12

def scrape
  @errors = []
  fetch && parse
rescue => error
  @errors << error
ensure
  return !errors?
end

#urlObject



29
30
31
# File 'lib/doctor_scrape/scraper/base.rb', line 29

def url
  @url
end