class OsuCtlScraper::Department

Constants

RESOURCE

Public Class Methods

all() click to toggle source

@return [Array<Hash>]

# File lib/osu-ctl-scraper/department.rb, line 6
def self.all
  html = get_html
  process_html(html)
end
get_html() click to toggle source

@return [String] html

# File lib/osu-ctl-scraper/department.rb, line 12
def self.get_html
  open("#{ENDPOINT}#{RESOURCE}").read
end
process_html(html) click to toggle source

@param [String] html @return [Array<Hash>]

# File lib/osu-ctl-scraper/department.rb, line 18
def self.process_html(html)
  departments = []
  ng = Nokogiri.HTML(html)
  ng.css("select[id='Dept'] option:not(:first-child)").each do |option|
    departments << process_option(option)
  end
  departments
end
process_option(option) click to toggle source

@param [String] option @return [Hash]

# File lib/osu-ctl-scraper/department.rb, line 29
def self.process_option(option)
  {
    subject_code: option["value"],
    title: process_title(option.text)
  }
end
process_title(title) click to toggle source

@param [String] title @return [String]

# File lib/osu-ctl-scraper/department.rb, line 38
def self.process_title(title)
  title.split(':')[1].strip
end