Class: MypageTools::SchedulePage

Inherits:
Object
  • Object
show all
Defined in:
lib/mypage_tools/schedule_page.rb

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ SchedulePage

Expects the myPage schedule page as a Nokogiri HTML object



4
5
6
# File 'lib/mypage_tools/schedule_page.rb', line 4

def initialize page
	@page = page
end

Instance Method Details

#shift_arrayObject

Gross & Ugly. Returns an array where every item is a Shift object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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_beginsObject

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



11
12
13
14
15
16
# 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