class MyBanner::Schedule

Constants

TABLE_SUMMARIES

Attributes

filepath[R]

Public Class Methods

new(filepath=nil) click to toggle source
# File lib/my_banner/schedule.rb, line 9
def initialize(filepath=nil)
  @filepath = filepath || "pages/my-detail-schedule.html"
  validate_file_exists
end

Public Instance Methods

doc() click to toggle source

@return Nokogiri::XML::Document

# File lib/my_banner/schedule.rb, line 41
def doc
  @doc ||= File.open(filepath) { |f| Nokogiri::XML(f) }
end
sections() click to toggle source
# File lib/my_banner/schedule.rb, line 14
def sections
  @sections ||= tablesets.map{ |tableset| tableset.section }
end
tables() click to toggle source

@return Nokogiri::XML::NodeSet

# File lib/my_banner/schedule.rb, line 36
def tables
  @tables ||= doc.css(".pagebodydiv").css("table").css(".datadisplaytable") # ignores the last table
end
tablesets() click to toggle source
# File lib/my_banner/schedule.rb, line 18
def tablesets
  @tablesets ||= tables.to_a.in_groups_of(3).map do |batch|
    summaries = batch.map { |t| t.attributes["summary"].value.squish }
    raise "Unexpected tableset: #{summaries}" unless summaries.sort == TABLE_SUMMARIES.values.sort
    info_table = batch.find { |t| t.attributes["summary"].value.squish == TABLE_SUMMARIES[:info].squish }
    enrollment_table = batch.find { |t| t.attributes["summary"].value == TABLE_SUMMARIES[:enrollment] }
    schedule_table = batch.find { |t| t.attributes["summary"].value == TABLE_SUMMARIES[:schedule] }
    Tableset.new(info_table, enrollment_table, schedule_table)
  end
end

Private Instance Methods

validate_file_exists() click to toggle source
# File lib/my_banner/schedule.rb, line 47
def validate_file_exists
  unless filepath && File.exists?(filepath)
    raise "Oh, couldn't find an HTML file at #{filepath}. Please download one and copy it to the expected location."
  end
end