Class: MypageTools::ScheduleScraper
- Inherits:
-
Object
- Object
- MypageTools::ScheduleScraper
- Includes:
- CapybaraWithPhantomJs
- Defined in:
- lib/mypage_tools/schedule_scraper.rb
Instance Method Summary collapse
- #generate_schedule ⇒ Object
-
#initialize(username, password) ⇒ ScheduleScraper
constructor
A new instance of ScheduleScraper.
- #next_week ⇒ Object
- #no_schedule_available? ⇒ Boolean
- #schedule_available? ⇒ Boolean
- #schedule_page ⇒ Object
Methods included from CapybaraWithPhantomJs
Constructor Details
#initialize(username, password) ⇒ ScheduleScraper
Returns a new instance of ScheduleScraper.
5 6 7 8 |
# File 'lib/mypage_tools/schedule_scraper.rb', line 5 def initialize username, password @username = username @password = password end |
Instance Method Details
#generate_schedule ⇒ Object
33 34 35 36 |
# File 'lib/mypage_tools/schedule_scraper.rb', line 33 def generate_schedule schedule = WeeklySchedule.new @schedule_page.week_begins, @schedule_page.shift_array schedule.to_ics end |
#next_week ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mypage_tools/schedule_scraper.rb', line 38 def next_week next_week_begins_date = Date.parse(@schedule_page.week_begins) + 7 if date_in_current_month? next_week_begins_date click_calendar_day(next_week_begins_date) @schedule_page = SchedulePage.new(Nokogiri::HTML.parse(page.html)) else click_next_month next_week_begins_date click_calendar_day(next_week_begins_date) @schedule_page = SchedulePage.new(Nokogiri::HTML.parse(page.html)) end end |
#no_schedule_available? ⇒ Boolean
29 30 31 |
# File 'lib/mypage_tools/schedule_scraper.rb', line 29 def no_schedule_available? page.has_text? "Schedule is not available for the selected week" end |
#schedule_available? ⇒ Boolean
25 26 27 |
# File 'lib/mypage_tools/schedule_scraper.rb', line 25 def schedule_available? page.has_text? /Schedule\sbegins\s\w+\s\d{1,2},\s\d{4}/ end |
#schedule_page ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mypage_tools/schedule_scraper.rb', line 10 def schedule_page unless @schedule_page new_session visit "/" wait_for(:wait_message => "Loading Login Page") { page.has_content? "Account Name" } login click_link "myTime" wait_for(:wait_message => "Loading Timecard") { page.has_content? "Current Timecard" } click_link "Schedule" wait_for(:wait_message => "Checking for available schedule") { schedule_available? } @schedule_page = SchedulePage.new(Nokogiri::HTML.parse(page.html)) end @schedule_page end |