Class: DoctorScrape::Scraper::Base
- Inherits:
-
Object
- Object
- DoctorScrape::Scraper::Base
- Defined in:
- lib/doctor_scrape/scraper/base.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #doc ⇒ Object
- #errors? ⇒ Boolean
- #fetch ⇒ Object
-
#initialize(url) ⇒ Base
constructor
A new instance of Base.
- #scrape ⇒ Object
- #url ⇒ Object
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/doctor_scrape/scraper/base.rb', line 5 def data @data end |
#errors ⇒ Object (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
#doc ⇒ Object
25 26 27 |
# File 'lib/doctor_scrape/scraper/base.rb', line 25 def doc @doc ||= Nokogiri::HTML @body end |
#errors? ⇒ Boolean
33 34 35 |
# File 'lib/doctor_scrape/scraper/base.rb', line 33 def errors? errors.any? end |
#fetch ⇒ Object
21 22 23 |
# File 'lib/doctor_scrape/scraper/base.rb', line 21 def fetch @body ||= open(url) end |
#scrape ⇒ Object
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 |
#url ⇒ Object
29 30 31 |
# File 'lib/doctor_scrape/scraper/base.rb', line 29 def url @url end |