rhs-schedule 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5f4b56aac9c5af3965c8a84dac2647175e3bdeb
4
+ data.tar.gz: cb30b9a7ad916b9b2c747f5631f4dc705dcd358a
5
+ SHA512:
6
+ metadata.gz: 76999fe34edc375a0a64ab1b406a78c7e29a1c921e217e75e6ae224b4c81f78406f900392cf431b06d392337823ed406aa70c3918811d817ee1fb8f7f149db1f
7
+ data.tar.gz: 0362805402a3df7e53b294d395e55ca4152c0fbe515b0d7f23898f26f3ff1b6e39e5adf03cc57aea6aa9ceab224c323856c7a926f3a1f917595b2ef3b9342f02
@@ -0,0 +1,135 @@
1
+ require 'date'
2
+ require 'json'
3
+
4
+ require_relative 'rhs-schedule/scheduleday'
5
+ require_relative 'rhs-schedule/period'
6
+
7
+ VERSION = '0.2.0'.freeze
8
+
9
+ # 05/25/16 08:50 AM
10
+ DATE_FORMAT = '%m/%d/%y'.freeze
11
+ TIME_FORMAT = '%I:%M %p'.freeze
12
+ DATETIME_FORMAT = "#{DATE_FORMAT} #{TIME_FORMAT}".freeze
13
+ EXCEPTIONS = ['0', '1', '2', '3', 'WEBEIM Scheduled', 'SIS Scheduled'].freeze
14
+
15
+ class ScheduleSystem
16
+ attr_reader :schedule_days
17
+
18
+ def initialize(path)
19
+ puts "Initializing Schedule System v#{VERSION}"
20
+ abort "Cannot find schedule text file at '#{path}'. Please download it from http://intranet.regis.org/downloads/outlook_calendar_import/outlook_schedule_download.cfm." unless File.file? path
21
+
22
+ @path = path
23
+ @classdays = []
24
+ @schedule_days = {}
25
+ parse
26
+ end
27
+
28
+ def get_sd date
29
+ if date.is_a? DateTime
30
+ @schedule_days[date]
31
+ else
32
+ date = Date.strptime(date, DATE_FORMAT)
33
+ @schedule_days[date]
34
+ end
35
+ end
36
+
37
+ def today
38
+ #false_date = Date.strptime('05/20/16', DATE_FORMAT)
39
+ @classdays.find { |cd| cd.schedule_day == @schedule_days[Date.parse(Time.now.to_s)]}
40
+ #@classdays.find { |cd| cd.schedule_day == @schedule_days[false_date] }
41
+ end
42
+
43
+ def parse
44
+ sds = [] # Schedule day lines
45
+ ps = [] # Period lines
46
+
47
+ File.open(@path, 'r') do |f|
48
+ f.each_line do |line|
49
+ next if line.include? 'Start Date' or line.strip.empty?
50
+
51
+ # Split the line and remove all the unnecessary values
52
+ values = line.split("\t")
53
+
54
+ # Determine schedule day or period
55
+ if line.include? ' Day'
56
+ # Use only date and schedule day
57
+ vital = [values[0], values[4]]
58
+ sds << vital
59
+ elsif values.length == 10
60
+ # Use only date, start time, end time, class name, and location
61
+ vital = [values[0], values[1], values[3], values[4], values[5]]
62
+ ps << vital
63
+ end
64
+ end
65
+ end
66
+
67
+ puts "Found #{ps.length} periods for #{sds.length} class days"
68
+
69
+ sds.each { |values| handle_schedule_day_line values }
70
+ handled = [] # Holds what schedules have been made
71
+ @schedule_days.each do |date, sd|
72
+ next if handled.include? sd
73
+
74
+ lines = ps.find_all { |values| values[0] == date.strftime(DATE_FORMAT) }
75
+ next if lines.empty?
76
+ create_class_day sd, lines
77
+ handled << sd
78
+ end
79
+ end
80
+
81
+ def handle_schedule_day_line values
82
+ date = Date.strptime(values[0], DATE_FORMAT)
83
+ sd = values[1][0] # A Day -> A
84
+ @schedule_days[date] = sd
85
+ end
86
+
87
+ def create_class_day sd, lines
88
+ periods = []
89
+ lines.each do |values|
90
+ # [date, start time, end time, class name, location]
91
+ course_title = values[3]
92
+ start_time = DateTime.strptime(values[1], TIME_FORMAT)
93
+ end_time = DateTime.strptime(values[2], TIME_FORMAT)
94
+ location = values[4]
95
+
96
+ periods << Period.new(course_title, start_time, end_time, location)
97
+ end
98
+
99
+ day = ScheduleDay.new(sd, periods)
100
+ fill_periods day
101
+ @classdays << day
102
+ end
103
+
104
+ # Take a just created periods list and fill in the holes (lunch and frees)
105
+ def fill_periods(day)
106
+ old = day.periods
107
+
108
+ # AM Advisement isn't in schedule text file
109
+ filled = [Period.new('Morning Advisement', DateTime.strptime('8:40 AM', TIME_FORMAT), DateTime.strptime('8:50 AM', TIME_FORMAT), 'Advisement')]
110
+
111
+ last_end = filled.first.end_time # Don't use old.first since the day could start with a free period
112
+ old.each do |p|
113
+ filled << Period.new('Unstructured Time', last_end, p.start_time, 'Anywhere') if p.start_time != last_end # I <3 Ruby
114
+
115
+ filled << p
116
+ last_end = p.end_time
117
+ end
118
+
119
+ if filled.last.end_time.strftime('%I:%M %p') != '02:50 PM'
120
+ end_time = DateTime.strptime('2:50 PM', TIME_FORMAT)
121
+ filled << Period.new('Unstructured Time', filled.last.end_time, end_time, 'Anywhere')
122
+ end
123
+
124
+ # PM Advisement isn't in schedule text file
125
+ filled << Period.new('Afternoon Advisement', DateTime.strptime('2:50 PM', TIME_FORMAT), DateTime.strptime('3:00 PM', TIME_FORMAT), 'Advisement')
126
+ day.periods = filled
127
+ end
128
+
129
+ def to_json(path)
130
+ puts 'Exporting schedule days to JSON'
131
+ File.open(path,'w') do |f|
132
+ f.write(JSON.pretty_generate(@schedule.schedule_days))
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,19 @@
1
+ class Period
2
+ attr_reader :start_time
3
+ attr_reader :end_time
4
+
5
+ def initialize(course, start_time, end_time, location)
6
+ @course_title = course
7
+ @start_time = start_time
8
+ @end_time = end_time
9
+ @location = location
10
+ end
11
+
12
+ def to_s
13
+ "#{@course_title} in #{@location} for #{duration} minutes"
14
+ end
15
+
16
+ def duration
17
+ ((@end_time - @start_time) * 24 * 60).to_i
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ class ScheduleDay
2
+ attr_reader :schedule_day
3
+
4
+ attr_writer :periods
5
+ attr_reader :periods
6
+
7
+ def initialize(sd, periods)
8
+ @schedule_day = sd
9
+ @periods = periods
10
+ end
11
+
12
+ def add_period(period)
13
+ @periods << period
14
+ end
15
+
16
+ def sort_periods
17
+ @periods.sort! { |a, b| a.start_time <=> b.start_time }
18
+ end
19
+
20
+ def to_s
21
+ to_return = ["#{@schedule_day}-Day: #{@periods.length} periods"]
22
+ @periods.each do |p|
23
+ to_return << " -#{p.to_s}"
24
+ end
25
+ to_return << "\n"
26
+
27
+ to_return.join("\n")
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rhs-schedule
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Frank Matranga
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A RubyGem that parses Regis High School's Intranet schedule download.
14
+ email: thefrankmatranga@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/rhs-schedule.rb
20
+ - lib/rhs-schedule/period.rb
21
+ - lib/rhs-schedule/scheduleday.rb
22
+ homepage:
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: A RegisHS schedule parser.
46
+ test_files: []