Class: Urgentcare::Scraper
- Inherits:
-
Object
- Object
- Urgentcare::Scraper
- Defined in:
- lib/UrgentCare/Scraper.rb
Constant Summary collapse
- @@client =
class variable
Selenium::WebDriver::Remote::Http::Default.new
- @@browser =
Watir::Browser.new :chrome, headless: true, http_client: @@client
- @@clinic_page =
@@browser.goto('https://www.carewellurgentcare.com/centers/')
- @@url =
[]
Class Method Summary collapse
-
.send_cmd(driver, cmd, params = {}) ⇒ Object
method by Hernando Torres- Rocca.
Instance Method Summary collapse
-
#get_appttime_date ⇒ Object
retrieve waittime and add to new office model.
-
#get_office_list ⇒ Object
called first in CLI.
-
#get_page ⇒ Object
page that lists all clinics.
-
#initialize(office = Urgentcare::Office, scraper: Urgentcare::Scraper) ⇒ Scraper
constructor
A new instance of Scraper.
- #make_office ⇒ Object
- #office_url ⇒ Object
Constructor Details
#initialize(office = Urgentcare::Office, scraper: Urgentcare::Scraper) ⇒ Scraper
Returns a new instance of Scraper.
5 6 7 8 |
# File 'lib/UrgentCare/Scraper.rb', line 5 def initialize(office = Urgentcare::Office, scraper: Urgentcare::Scraper) @office = office @scraper = scraper end |
Class Method Details
.send_cmd(driver, cmd, params = {}) ⇒ Object
method by Hernando Torres- Rocca
10 11 12 13 14 15 16 |
# File 'lib/UrgentCare/Scraper.rb', line 10 def self.send_cmd(driver, cmd, params={}) #method by Hernando Torres- Rocca bridge = driver.send(:bridge) resource = "session/#{bridge.session_id}/chromium/send_command_and_get_result" response = bridge.http.call(:post, resource, {'cmd':cmd, 'params': params}) raise response[:value] if response[:status] return response[:value] end |
Instance Method Details
#get_appttime_date ⇒ Object
retrieve waittime and add to new office model
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/UrgentCare/Scraper.rb', line 54 def get_appttime_date #retrieve waittime and add to new office model sleep(1); iframe_info = Nokogiri::HTML(@js_doc.html) if !iframe_info.css('div.time-slots').empty? @wait_day = iframe_info.css('div.d-flex.d-md-none.header').text @wait_time = iframe_info.css('div.time-slot.selected').text @office.all[$index].next_available = "#{@wait_day} #{@wait_time}" else @wait_time = "Walk-in only due to staffing shortages" @office.all[$index].next_available = "#{@wait_time}" end end |
#get_office_list ⇒ Object
called first in CLI
34 35 36 37 |
# File 'lib/UrgentCare/Scraper.rb', line 34 def get_office_list #called first in CLI @new_page = get_page.css('p')[2..] office_url end |
#get_page ⇒ Object
page that lists all clinics
29 30 31 32 |
# File 'lib/UrgentCare/Scraper.rb', line 29 def get_page # page that lists all clinics doc = @@browser.div(id: 'et-main-area').wait_until(&:present?) inner = Nokogiri::HTML(doc.inner_html) #return value of the method end |
#make_office ⇒ Object
47 48 49 50 51 52 |
# File 'lib/UrgentCare/Scraper.rb', line 47 def make_office @off = @office.new @off.name = @office_details.css('a')[0].text @off.url = @office_details.css('a')[0][name="href"] @off.phone_number = @office_details.css('a[href]')[1].text end |
#office_url ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/UrgentCare/Scraper.rb', line 39 def office_url @new_page.each do |office_details| #does not create additional objects. returns original object @@url << office_details @office_details = office_details make_office end end |