Class: Tableau::TimetableParser
- Inherits:
-
BaseParser
- Object
- BaseParser
- Tableau::TimetableParser
- Defined in:
- lib/tableau/timetableparser.rb
Constant Summary collapse
- @@TIMETABLE_CODE_REGEX =
/^[A-Za-z0-9\(\)]+/
Instance Method Summary collapse
-
#initialize(student_set_id = nil) ⇒ TimetableParser
constructor
Create a new TimetableParser, with a Student Set ID (aka Core Timetable).
-
#parse ⇒ Object
Parse the Timetable for all Modules within Returns: A Tableau::Timetable.
-
#sort_classes(timetable, classes) ⇒ Object
Sort all the parsed classes into modules.
-
#timetable_info ⇒ Object
Get a summary of information about this timetable.
Methods inherited from BaseParser
#create_class, #create_class_weeks, #get_info, #inc_time, #initalize, #parse_table, #xpath_for_table
Constructor Details
#initialize(student_set_id = nil) ⇒ TimetableParser
Create a new TimetableParser, with a Student Set ID (aka Core Timetable)
9 10 11 12 13 14 15 16 |
# File 'lib/tableau/timetableparser.rb', line 9 def initialize(student_set_id = nil) begin = Tableau::UriBuilder.new(student_set_id).read @raw_timetable = Nokogiri::HTML() if rescue OpenURI::HTTPError return nil end end |
Instance Method Details
#parse ⇒ Object
Parse the Timetable for all Modules within Returns: A Tableau::Timetable
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tableau/timetableparser.rb', line 24 def parse raise "No Timetable loaded!" unless @raw_timetable table_info = @@TIMETABLE_CODE_REGEX.match(get_info(@raw_timetable)) = Tableau::Timetable.new(table_info) table_count = 1 table_data = @raw_timetable.xpath(xpath_for_table(table_count)) while !table_data.empty? table_classes = parse_table(table_data) sort_classes(, table_classes) table_data = @raw_timetable.xpath(xpath_for_table(table_count += 1)) end end |
#sort_classes(timetable, classes) ⇒ Object
Sort all the parsed classes into modules
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tableau/timetableparser.rb', line 42 def sort_classes(, classes) classes.each do |c| if !(cmodule = .module_for_code(c.code)) cmodule = Tableau::Module.new(c.code) .push_module(cmodule) end cmodule.add_class(c) end end |
#timetable_info ⇒ Object
Get a summary of information about this timetable
19 20 |
# File 'lib/tableau/timetableparser.rb', line 19 def end |