Class: KielcePlugins::Schedule::Schedule
- Inherits:
-
Object
- Object
- KielcePlugins::Schedule::Schedule
- Defined in:
- lib/kielce_plugins/schedule/schedule.rb
Constant Summary collapse
- SCHEDULE_KEYS =
SCHEDULE_KEYS = [:week, :date, :topics, :notes, :reading, :milestones, :comments]
[:week, :date, :topics, :reading, :milestones, :comments]
Instance Attribute Summary collapse
-
#assignments ⇒ Object
Returns the value of attribute assignments.
-
#schedule_days ⇒ Object
Returns the value of attribute schedule_days.
Instance Method Summary collapse
- #assignment_list ⇒ Object
- #assignment_style ⇒ Object
- #build_assignments(rows) ⇒ Object
- #build_rows(worksheet, keys) ⇒ Object
- #build_schedule_days(schedule_rows) ⇒ Object
-
#initialize(filename) ⇒ Schedule
constructor
A new instance of Schedule.
- #lab_list ⇒ Object
- #timeline_page ⇒ Object
- #timeline_style ⇒ Object
- #timeline_table ⇒ Object
- #transform(value, rowDate, end_of_semester) ⇒ Object
Constructor Details
#initialize(filename) ⇒ Schedule
Returns a new instance of Schedule.
15 16 17 18 19 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 15 def initialize(filename) workbook = RubyXL::Parser.parse(filename) @assignments = build_assignments(build_rows(workbook["Assignments"], Assignment::ASSIGNMENT_KEYS)) @schedule_days = build_schedule_days(build_rows(workbook["Schedule"], SCHEDULE_KEYS)) end |
Instance Attribute Details
#assignments ⇒ Object
Returns the value of attribute assignments.
13 14 15 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 13 def assignments @assignments end |
#schedule_days ⇒ Object
Returns the value of attribute schedule_days.
13 14 15 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 13 def schedule_days @schedule_days end |
Instance Method Details
#assignment_list ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 293 def assignment_list list = <<TABLE <table class='kielceAssignmentTable'> <tr> <th>Due</th> <th>Name</th> <th>Details</th> </tr> TABLE by_date = @assignments.values.reject { |item| item.due.nil? || item.type == "Lab" }.sort_by { |a| a.due } by_date.each do |assignment| list += " <tr>" list += " <td class='kielceAssignmentTable_due'>#{assignment.due.strftime("%a. %-d %b.")}</td>\n" list += " <td class='kielceAssignmentTable_title'>#{assignment.title(:full, true)}</td>\n" list += " <td class='kielceAssignmentTable_details'>#{assignment.details}</td>\n" list += " </tr>\n\n" end list += "</table>\n" end |
#assignment_style ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 265 def assignment_style <<STYLE .kielceAssignmentTable { border-spacing: 35px 0; } .kielceAssignmentTable tr th { text-align: left; } .kielceAssignmentTable tr td { vertical-align: top; } .kielceAssignmentTable_due { white-space: nowrap; } .kielceAssignmentTable_title { white-space: nowrap; } .exam { background-color: lightgreen; } STYLE end |
#build_assignments(rows) ⇒ Object
111 112 113 114 115 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 111 def build_assignments(rows) assignment_hash = {} rows.each { |row| assignment_hash[row[:id]] = Assignment.new(row) } assignment_hash end |
#build_rows(worksheet, keys) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 76 def build_rows(worksheet, keys) row_date = nil end_of_semester = nil # Remove the first (header) row, and any empty rows. # Also, remove any rows after "END" first = true done = false rows = [] worksheet.each do |row| done = true if !row.nil? && !row[0].nil? && row[0].value == "END" if !row.nil? && !row[0].nil? && row[0].value.is_a?(String) && (row[0].value =~ /^EO(T|S)$/) end_of_semester = row[1].value $stderr.puts "Found end of semester marker: #{end_of_semester}" end unless first || row.nil? || done rows << row end first = false end # For each row, build a Hash describing the row. rows.map do |row| row_hash = { original: {} } keys.each_with_index do |item, index| row_date = row[index].value if item == :date && !row[index].nil? && !row[index].value.nil? row_hash[:original][item] = row[index].nil? ? nil : row[index].value row_hash[item] = row[index].nil? ? nil : transform(row[index].value, row_date, end_of_semester) end row_hash end # end map end |
#build_schedule_days(schedule_rows) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 117 def build_schedule_days(schedule_rows) array_keys = SCHEDULE_KEYS.slice(2, SCHEDULE_KEYS.length - 2) current_week = nil schedule_days = [] schedule_day = nil schedule_rows.each do |row| # if there is a date, start a new day unless row[:date].nil? # push day in progress into array schedule_days << schedule_day unless schedule_day.nil? # create a new schedule_day Hash schedule_day = { begin_week: false, } unless row[:week].nil? current_week = row[:week] schedule_day[:begin_week] = true end schedule_day[:week] = current_week schedule_day[:date] = row[:date] array_keys.each { |key| schedule_day[key] = [] } end # push non-nil values onto the corresponding array # array_keys.each { |key| schedule_day[key] << row[key] unless row[key].nil? } array_keys.each do |key| val = row[key] # skip any completely empty cells (they produce a value of nil) # Replace a single period with a whitespace. (Thus producing an empty cell in the table) # Similarly, treat cells beginnign with // as a comment and produce an empty cell in the table) unless row[key].nil? val = " " if val == "." || val =~ /^\s*\/\// schedule_day[key] << val end end # Look for assignments / due dates and add information to @assignment objects original_milestones = row[:original][:milestones] if !original_milestones.nil? && original_milestones =~ /<<due\s+(.*)>>/ #$stderr.puts "Assignment #{$1} has due date of #{schedule_day[:date].strftime("%a. %-d %b.")}" @assignments[$1].due = schedule_day[:date] end if !original_milestones.nil? && original_milestones =~ /<<assign\s+(.*)>>/ #$stderr.puts "Assignment #{$1} has assignment date of #{schedule_day[:date].strftime("%a. %-d %b.")}" unless @assignments.has_key?($1) $stderr.puts "Key #{$1} not found in #{@assignments.keys.inspect}" end @assignments[$1].assigned = schedule_day[:date] end end # end each row schedule_days << schedule_day unless schedule_day.nil? schedule_days end |
#lab_list ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 314 def lab_list list = <<TABLE <table class='kielceAssignmentTable'> <tr> <th>Date</th> <th>Name</th> <th>Details</th> </tr> TABLE assigned_labs = @assignments.values.select { |item| item.type == "Lab" && !item.assigned.nil? } by_date = assigned_labs.sort { |a, b| a.assigned <=> b.assigned } by_date.each do |assignment| list += " <tr>" list += " <td class='kielceAssignmentTable_due'>#{assignment.assigned.strftime("%a. %-d %b.")}</td>\n" list += " <td class='kielceAssignmentTable_title'>#{assignment.title(:full, true)}</td>\n" list += " <td class='kielceAssignmentTable_details'>#{assignment.details}</td>\n" list += " </tr>\n\n" end list += "</table>\n" list end |
#timeline_page ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 250 def timeline_page <<PAGE <html> <head> <style> #{timeline_style} </style> </head> <body> #{timeline_table} </body> </html> PAGE end |
#timeline_style ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 224 def timeline_style <<STYLE table.kielceSchedule { border-collapse: separate; border-spacing: 2px; } .kielceSchedule tr th { text-align: left; } .kielceSchedule tr td { vertical-align: top; padding-right: 10px; } .week_column, .date_column { white-space: nowrap; } .kielceSchedule tr th, .date_column, .topics_column, .notes_column, .reading_column, .milestones_column, .week_end td { border-bottom: 1px solid; } STYLE end |
#timeline_table ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 180 def timeline_table table = [] table << <<TABLE <table class='kielceSchedule'> <tr> <th>Week</th> <th>Date</th> <th>Topics</th> <!-- <th>Notes</th> --> <th>Reading</th> <th>Milestones</th> </tr> TABLE first = true @schedule_days.each do |schedule_day| table << "<tr>" if schedule_day[:begin_week] unless first # Add a blank row of horizontal lines table << "<td></td><td></td><td></td><td></td><td></td><td></td></tr>" table << "<tr class='week_end'><td></td><td></td><td></td><td></td><td></td><td></td></tr>" table << "<tr>" end first = false week_value = schedule_day[:week] else week_value = "" end table << " <td class='week_column'>#{week_value}</td>" formatted_date = schedule_day[:date].strftime("%a. %-d %b.") table << " <td class='date_column'>#{formatted_date}</td>" table << " <td class='topics_column'>#{schedule_day[:topics].join("<br>")}</td>" # table << " <td class='topics_column'>#{schedule_day[:notes].join("<br>")}</td>" table << " <td class='reading_column'>#{schedule_day[:reading].join("<br>")}</td>" table << " <td class='milestones_column'>#{schedule_day[:milestones].join("<br>")}</td>" table << "</tr>" end table << "</table>" table.join("\n") end |
#transform(value, rowDate, end_of_semester) ⇒ Object
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kielce_plugins/schedule/schedule.rb', line 21 def transform(value, rowDate, end_of_semester) if value.is_a? String # Replace link markup value.gsub!(/\[\[([^\s]+)(\s+(\S.*)|\s*)\]\]/) do text = $3.nil? ? "<code>#{$1}</code>" : $3 "<a target='_blank' href='#{$1}'>#{text}</a>" end value.gsub!(/<<(assign|due|ref)\s+(\S.+?)>>/) do #$stderr.puts "Found assignment ref #{$1} --- #{$2} -- #{@assignments[$2].inspect}" unless @assignments.has_key?($2) $stderr.puts "Assignment #{$2} not found" exit(1) end text = @assignments[$2].title(:full, true) if $1 == "assign" "Assign #{text}" elsif $1 == "due" "<b>Due</b> #{text}" elsif $1 == "ref" text else $stderr.puts "Unexpected match #{$1}" end end # end gsub! value.gsub!(/{{([^{}:]+):\s*([^{}]+)}}/) do text = $1 link_rule = $2 # $stderr.puts "Processing text #{text} with link rule #{link_rule}" if (link_rule =~ /(.*)\!(.+)/) method = $1 param = $2 method = "default" if method.empty? # $stderr.puts "Found link rule =>#{method}<= #{method.empty?} =>#{param}<=" link = $d.course.notesTemplates.method_missing(method, param) else link = link_rule end # Don't provide links to notes if we haven't gone through those notes in lecture yet. suppress = text =~ /^xx/ || (text=~ /^td_/ && (rowDate >= Date.today - 3 || Date.today >= end_of_semester)) text = text.gsub(/^td_/, "") # Suppress links if text begins with xx. suppress ? "" : "(<a target='_blank' href='#{link}'>#{text}</a>)" end # end gsub end # end if value is string value end |