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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b306e3e05a4496b0a3e0fa562ece24605badbc2
4
- data.tar.gz: e82827d0886d4791bda545235a88d9acf7db8b72
3
+ metadata.gz: 826ff7f66f9e86f1b983d7343e0eff0db2dc5341
4
+ data.tar.gz: 9e21305d673aa17a0bcd1632a400a26eec715f67
5
5
  SHA512:
6
- metadata.gz: a4a85f0ddf8932ba2cb349cc83fd58dcd0b31a68e2c989cd384d8651342aef38e47dd6f256bd82632efa19ffddd22964d71c4837ea40fd1480ba0bed1f039949
7
- data.tar.gz: cd46ede9986f950067f7b7e3fce5c5b217081d93925d8cf0958cd0735421042f5fdabafdbf2470cf50f6ecddb95d8f9afa9a4a22d4ba9a7614e146a579e30fcf
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.8.0'.freeze
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
- puts "Initializing Schedule System v#{VERSION}"
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhs-schedule
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Matranga