From ee582734acbffa328c326d7b2a3561f63b9bfc56 Mon Sep 17 00:00:00 2001 From: Pito Salas Date: Tue, 3 Jan 2017 17:28:16 -0500 Subject: [PATCH] before changing time scheduling logic --- lib/coursegen/course/data/citem.rb | 2 + lib/coursegen/course/data/lectures.rb | 145 +++++++++--------- lib/coursegen/course/data/section_def.rb | 12 +- .../course/helpers/ical_feed_helpers.rb | 2 +- lib/coursegen/course/helpers/list_of.rb | 16 +- .../course/schedule/schedule_feed.rb | 4 +- lib/coursegen/version.rb | 2 +- 7 files changed, 93 insertions(+), 90 deletions(-) diff --git a/lib/coursegen/course/data/citem.rb b/lib/coursegen/course/data/citem.rb index 25326ac..f73a859 100644 --- a/lib/coursegen/course/data/citem.rb +++ b/lib/coursegen/course/data/citem.rb @@ -1,3 +1,4 @@ +require 'byebug' require 'active_support/inflector' # @@ -52,6 +53,7 @@ def lecture_date_s def schedule_start_date_time return if @lecture_date.nil? +byebug schedule = Toc.instance.section(@section).schedule lecture_date + schedule.start_time end diff --git a/lib/coursegen/course/data/lectures.rb b/lib/coursegen/course/data/lectures.rb index 81aa633..a023aaa 100644 --- a/lib/coursegen/course/data/lectures.rb +++ b/lib/coursegen/course/data/lectures.rb @@ -1,91 +1,92 @@ require 'tree' class Lectures < Section - def initialize(sect, citems, schedule=nil, collapsed=false) - super sect, citems, collapsed - @schedule = schedule || ::Scheduler.new - @citems = sort_items - build_tree - end + def initialize(sect, citems, schedule=nil, collapsed=false) + super sect, citems, collapsed + @schedule = schedule || ::Scheduler.new + @citems = sort_items + build_tree + end - def has_subsections? - true - end + def has_subsections? + true + end - def has_lecture_numbers? - true - end + def has_lecture_numbers? + true + end - def schedule - @schedule - end + def schedule + @schedule + end - def build_tree - lecture_num = 1 - @root = Tree::TreeNode.new("root", "root") - @citems.each do |i| - i.lecture_number = lecture_num - i.lecture_date = @schedule.event_date_by_index(lecture_num - 1) # Lecture numbers are base 1 - if i.type == "subsection" - @root.add(Tree::TreeNode.new(i.subsection, i)) - elsif i.type == "page" - parent_tree_node = parent_node_of(i) - parent_tree_node.add(Tree::TreeNode.new(i.identifier, i)) - lecture_num += 1 - else - raise ArgumentError, "invalid lecture page type of #{i.type}for #{i.title}" - end - end - end + def build_tree + lecture_num = 1 + @root = Tree::TreeNode.new("root", "root") + @citems.each do |i| + i.lecture_number = lecture_num + i.lecture_date = @schedule.event_date_by_index(lecture_num - 1) # Lecture numbers are base 1 + if i.type == "subsection" + @root.add(Tree::TreeNode.new(i.subsection, i)) + elsif i.type == "page" + parent_tree_node = parent_node_of(i) + parent_tree_node.add(Tree::TreeNode.new(i.identifier, i)) + lecture_num += 1 + else + raise ArgumentError, "invalid lecture page type of #{i.type}for #{i.title}" + end + end + end - def parent_node_of citem - parent_node = @root[citem.subsection] - raise RuntimeError, "Cant find section for item: #{citem.identifier}" if parent_node.nil? - parent_node - end + def parent_node_of citem + parent_node = @root[citem.subsection] + raise RuntimeError, "Cant find section for item: #{citem.identifier}" if parent_node.nil? + parent_node + end - def treenode_of citem - @root.find do - |tree_node| - if citem.type == "subsection" - citem.subsection == tree_node.name - else - citem.identifier == tree_node.name - end - end - end + def treenode_of citem + @root.find do |tree_node| + if citem.type == "subsection" + citem.subsection == tree_node.name + else + citem.identifier == tree_node.name + end + end + end - def subsections - @root.children - end + def subsections + @root.children + end - def next_for(citem) - next_node = treenode_of(citem).next_sibling - if !next_node.nil? - next_node.content - else - citem - end - end + def next_for(citem) + next_node = treenode_of(citem).next_sibling + if !next_node.nil? + next_node.content + else + citem + end + end - def previous_for(citem) - prev_node = treenode_of(citem).previous_sibling - if !prev_node.nil? - prev_node.content - else - citem - end - end + def previous_for(citem) + prev_node = treenode_of(citem).previous_sibling + if !prev_node.nil? + prev_node.content + else + citem + end + end -protected + protected # # Sort all the items in this section: First by the ordering of the subseciton # that the item belongs to, and second by the item's own indicated order. # - def sort_items - new_citems = @citems.sort_by { |i| [ lookup_citem_by_identifier(i.subsection+"index.html").order, ((i.type == "page" ? 100 : 1 ) * i.order) ] } - @items = new_citems - end - + def sort_items + new_citems = @citems.sort_by do |i| + [lookup_citem_by_identifier(i.subsection + "index.html").order, + ((i.type == "page" ? 100 : 1) * i.order)] + end + @items = new_citems + end end diff --git a/lib/coursegen/course/data/section_def.rb b/lib/coursegen/course/data/section_def.rb index 4654290..1a27583 100644 --- a/lib/coursegen/course/data/section_def.rb +++ b/lib/coursegen/course/data/section_def.rb @@ -1,10 +1,10 @@ # Sidebar configuration class SectionDef - attr_accessor :title, :selector, :options - def initialize(title, selector, options = {}) - @title = title - @selector = selector - @options = options - end + attr_accessor :title, :selector, :options + def initialize(title, selector, options = {}) + @title = title + @selector = selector + @options = options + end end diff --git a/lib/coursegen/course/helpers/ical_feed_helpers.rb b/lib/coursegen/course/helpers/ical_feed_helpers.rb index 4169a8c..96da415 100644 --- a/lib/coursegen/course/helpers/ical_feed_helpers.rb +++ b/lib/coursegen/course/helpers/ical_feed_helpers.rb @@ -1,7 +1,7 @@ module ICalFeedHelpers def generate_ical source data_adaptor = DataAdaptor.new(source) - ical_adaptor = ICalAdaptor.new() + ical_adaptor = ICalAdaptor.new schedule_feed = ScheduleFeed.new(ical_adaptor, data_adaptor) schedule_feed.render end diff --git a/lib/coursegen/course/helpers/list_of.rb b/lib/coursegen/course/helpers/list_of.rb index 47e0093..febc287 100644 --- a/lib/coursegen/course/helpers/list_of.rb +++ b/lib/coursegen/course/helpers/list_of.rb @@ -1,5 +1,4 @@ class ListOf - # source: name of a section as a string # rows: array with one or more of: # "pages" @@ -56,13 +55,13 @@ def generate_rows end def generate_detail_row(row_id) - @mark.row_begin - @cols.each do |col_selector| - @mark.cell_begin - @mark.cell_content(cell_content_string(row_id, col_selector, detail: true)) - @mark.cell_end - end - @mark.row_end + @mark.row_begin + @cols.each do |col_selector| + @mark.cell_begin + @mark.cell_content(cell_content_string(row_id, col_selector, detail: true)) + @mark.cell_end + end + @mark.row_end end def generate_summary_row(row_id) @@ -99,5 +98,4 @@ def include_by_subsection_path?(row_id) def subsection_hdr?(row_id) row_id.type == "subsection" end - end diff --git a/lib/coursegen/course/schedule/schedule_feed.rb b/lib/coursegen/course/schedule/schedule_feed.rb index 111cc2e..c956309 100644 --- a/lib/coursegen/course/schedule/schedule_feed.rb +++ b/lib/coursegen/course/schedule/schedule_feed.rb @@ -1,4 +1,6 @@ -# Used in generating iCal feed. Given a data_adapter (who knows how to get data out and iterate across things) and a feed_builder (who knows how to turn that data into some kind of feed), produce the feed. This same class could also generate, for example, an RSs feed. +# Used in generating iCal feed. Given a data_adapter (who knows how to get data out and iterate across things) and a +# feed_builder (who knows how to turn that data into some kind of feed), produce the feed. This same class could also +# generate, for example, an RSs feed. class ScheduleFeed def initialize feed_builder, data_adapter diff --git a/lib/coursegen/version.rb b/lib/coursegen/version.rb index 4d76841..4d1cb6d 100644 --- a/lib/coursegen/version.rb +++ b/lib/coursegen/version.rb @@ -1,3 +1,3 @@ module Coursegen - VERSION = "0.3.2" + VERSION = "0.4.0" end