Class: OsuCtlScraper::Department

Inherits:
Object
  • Object
show all
Defined in:
lib/osu-ctl-scraper/department.rb

Constant Summary collapse

RESOURCE =
"/faculty/textbooks/"

Class Method Summary collapse

Class Method Details

.allArray<Hash>

Returns:

  • (Array<Hash>)


6
7
8
9
# File 'lib/osu-ctl-scraper/department.rb', line 6

def self.all
  html = get_html
  process_html(html)
end

.get_htmlString

Returns html.

Returns:

  • (String)

    html



12
13
14
# File 'lib/osu-ctl-scraper/department.rb', line 12

def self.get_html
  open("#{ENDPOINT}#{RESOURCE}").read
end

.process_html(html) ⇒ Array<Hash>

Parameters:

  • html (String)

Returns:

  • (Array<Hash>)


18
19
20
21
22
23
24
25
# 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) ⇒ Hash

Parameters:

  • option (String)

Returns:

  • (Hash)


29
30
31
32
33
34
# 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) ⇒ String

Parameters:

  • title (String)

Returns:

  • (String)


38
39
40
# File 'lib/osu-ctl-scraper/department.rb', line 38

def self.process_title(title)
  title.split(':')[1].strip
end