rhs-schedule 0.8.0 → 0.9.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.
- checksums.yaml +4 -4
- data/lib/rhs-schedule.rb +38 -5
- data/lib/rhs-schedule/exports.rb +36 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 826ff7f66f9e86f1b983d7343e0eff0db2dc5341
|
4
|
+
data.tar.gz: 9e21305d673aa17a0bcd1632a400a26eec715f67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9cff6a2c9a3ce62ab910e309395c4145d7fb616075762b3667050ff9d6fcff2957057bb68f120d47c9d9aa6093a8e176f49ba4e0a5ffd027a80d7e7c4d5d042
|
7
|
+
data.tar.gz: 948799766f39e24342fcce95de19e263767a7e3639dc0dd125c9d5a68376efa8070b714c8ebaa4ba98b8722e940823981acffd59f9a330dd89d1fd48cc7e49ab
|
data/lib/rhs-schedule.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative 'rhs-schedule/period'
|
|
6
6
|
require_relative 'rhs-schedule/exports'
|
7
7
|
require_relative 'rhs-schedule/errors'
|
8
8
|
|
9
|
-
VERSION = '0.
|
9
|
+
VERSION = '0.9.0'.freeze
|
10
10
|
|
11
11
|
# e.g. 05/25/16
|
12
12
|
DATE_FORMAT = '%m/%d/%y'.freeze
|
@@ -35,8 +35,9 @@ class ScheduleSystem
|
|
35
35
|
# If it cannot read the file or it detects that the format of the file is invalid the program aborts.
|
36
36
|
#
|
37
37
|
# @param path [String] the path to the text file (not the folder!)
|
38
|
-
def initialize(path)
|
39
|
-
|
38
|
+
def initialize(path, silent=false)
|
39
|
+
@silent = silent
|
40
|
+
puts "Initializing Schedule System v#{VERSION}" unless @silent
|
40
41
|
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
|
41
42
|
|
42
43
|
@path = path
|
@@ -61,12 +62,44 @@ class ScheduleSystem
|
|
61
62
|
|
62
63
|
# Displays formatted info on the current day, including it's schedule day and classes in order.
|
63
64
|
#
|
64
|
-
# @return [ScheduleDay] The ScheduleDay object.
|
65
|
+
# @return [ScheduleDay, nil] The ScheduleDay object, or nil if today is not a school day.
|
65
66
|
def today
|
66
67
|
#false_date = Date.strptime('05/20/16', DATE_FORMAT)
|
67
68
|
@class_days[@schedule_days[Date.parse(Time.now.to_s)]]
|
68
69
|
end
|
69
70
|
|
71
|
+
# Gets the the letter of the schedule day of the date passed.
|
72
|
+
#
|
73
|
+
# @param date [String, Date, DateTime] the date
|
74
|
+
# @return [ScheduleDay, nil] the letter or nil if the date is not a school day
|
75
|
+
def get_schedule_day(date)
|
76
|
+
d = nil
|
77
|
+
if date.is_a? String
|
78
|
+
d = Date.strptime(date, DATE_FORMAT)
|
79
|
+
elsif date.is_a? DateTime
|
80
|
+
d = date.to_date
|
81
|
+
end
|
82
|
+
|
83
|
+
return @schedule_days[d]
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
# Gets the the periods and schedule day of the passed date.
|
88
|
+
#
|
89
|
+
# @param date [String, Date, DateTime]
|
90
|
+
# @return [ScheduleDay, nil] the ScheduleDay object or nil if the date passed is not a school day
|
91
|
+
def get_class_day(date)
|
92
|
+
d = nil
|
93
|
+
|
94
|
+
if date.is_a? String
|
95
|
+
d = Date.strptime(date, DATE_FORMAT)
|
96
|
+
elsif date.is_a? DateTime
|
97
|
+
d = date.to_date
|
98
|
+
end
|
99
|
+
|
100
|
+
return @class_days[@schedule_days[d]]
|
101
|
+
end
|
102
|
+
|
70
103
|
# Gets the current period object of the currently ongoing class (if today is a school day).
|
71
104
|
#
|
72
105
|
# @return [Period, nil] the Period object of the current class or nil if not a school day or school is over
|
@@ -134,7 +167,7 @@ class ScheduleSystem
|
|
134
167
|
end
|
135
168
|
end
|
136
169
|
|
137
|
-
puts "Found #{ps.length} periods for #{sds.length} class days"
|
170
|
+
puts "Found #{ps.length} periods for #{sds.length} class days" unless @silent
|
138
171
|
|
139
172
|
sds.each { |values| handle_schedule_day_line values }
|
140
173
|
handled = [] # Holds what schedules have been made
|
data/lib/rhs-schedule/exports.rb
CHANGED
@@ -95,4 +95,40 @@ module Exports
|
|
95
95
|
|
96
96
|
puts "TSV schedule file exported to '#{path}'"
|
97
97
|
end
|
98
|
+
|
99
|
+
def export_schedule_days(path, separator="\t")
|
100
|
+
headers = ['Date', 'Schedule Day']
|
101
|
+
tsv_file = File.open(path, 'w')
|
102
|
+
tsv_file.puts(headers.join(separator))
|
103
|
+
@schedule.schedule_days.each do |date, letter|
|
104
|
+
date_str = date.strftime(DATE_FORMAT)
|
105
|
+
values = [date_str, letter]
|
106
|
+
tsv_file.puts(values.join(separator))
|
107
|
+
end
|
108
|
+
|
109
|
+
tsv_file.close
|
110
|
+
puts "schedule days exported to '#{path}'"
|
111
|
+
end
|
112
|
+
|
113
|
+
def classdays_to_tsv(path, include_advisements=false, include_frees=false)
|
114
|
+
headers = ['Schedule Day', 'Subject', 'Start Time', 'End Time', 'Location']
|
115
|
+
|
116
|
+
tsv_file = File.open(path, 'w')
|
117
|
+
tsv_file.puts(headers.join("\t"))
|
118
|
+
|
119
|
+
# 1 line per period in year
|
120
|
+
@schedule.class_days.each do |letter, schedule_day|
|
121
|
+
periods = schedule_day.periods
|
122
|
+
periods = periods.select { |p| p.course_title != 'Unstructured Time' } unless include_frees
|
123
|
+
periods = periods.select { |p| p.course_title != 'Morning Advisement' and p.course_title != 'Afternoon Advisement' } unless include_advisements
|
124
|
+
|
125
|
+
periods.each do |p|
|
126
|
+
values = [letter, p.course_title, p.start_time.strftime(TIME_FORMAT), p.end_time.strftime(TIME_FORMAT), p.location]
|
127
|
+
tsv_file.puts(values.join("\t"))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
tsv_file.close
|
131
|
+
|
132
|
+
puts "class days TSV schedule file exported to '#{path}'"
|
133
|
+
end
|
98
134
|
end
|