class MypageTools::SchedulePage
Public Class Methods
new(page)
click to toggle source
Expects the myPage schedule page as a Nokogiri HTML object
# File lib/mypage_tools/schedule_page.rb, line 4 def initialize page @page = page end
Public Instance Methods
shift_array()
click to toggle source
Gross & Ugly. Returns an array where every item is a Shift
object
# File lib/mypage_tools/schedule_page.rb, line 20 def shift_array unless @shift_array @shift_array = [] days_of_week = %w[Saturday Sunday Monday Tuesday Wednesday Thursday Friday] # Establishing variable scope current_day = nil current_date = nil index_counter = 0 shift = nil # Finds a day then creates shifts for that day from each following pair of times raw_schedule_array.each do |item| if days_of_week.member?(item) current_day = item # Figure out the date of the shift based on the day of the week & start date of the week current_date = Date.parse(week_begins) + days_of_week.index(item) index_counter = 0 elsif index_counter == 0 shift = Shift.new shift.day_of_week = current_day shift.date = current_date shift.start = item index_counter += 1 elsif index_counter == 1 shift.stop = item index_counter = 0 @shift_array << shift end end end @shift_array end
week_begins()
click to toggle source
Return string containing the date the week begins, i.e. “Sep 14, 2013” Matches from the raw_schedule_text
using a regex rubular.com/r/OjRZ0q6cko
# File lib/mypage_tools/schedule_page.rb, line 11 def week_begins unless @week_begins @week_begins = raw_schedule_text.scan(/\w+\s\d{1,2},\s\d{4}/)[0] end @week_begins end
Private Instance Methods
raw_schedule_array()
click to toggle source
Data structure for schedule: [Day, Start, End, Day, Start, End, (Start), (End), etc…] Matched from the raw_schedule_text
with a regex rubular.com/r/xOOFBOKFMM
# File lib/mypage_tools/schedule_page.rb, line 67 def raw_schedule_array unless @raw_schedule_array @raw_schedule_array = raw_schedule_text.scan /[SMTWF]\w{2,5}day|\d{1,2}:\d{2}[A|P]M/ end @raw_schedule_array end
raw_schedule_text()
click to toggle source
Returns a string with all the necessary information to extract that week’s schedule
# File lib/mypage_tools/schedule_page.rb, line 56 def raw_schedule_text unless @raw_schedule_text xpath_to_schedule = "//div[@id = 'contentTimecard']/div/table/tbody/tr/td/table/tbody" @raw_schedule_text = @page.search(xpath_to_schedule).text end @raw_schedule_text end