Class: OsuCtlScraper::Department
- Inherits:
-
Object
- Object
- OsuCtlScraper::Department
- Defined in:
- lib/osu-ctl-scraper/department.rb
Constant Summary collapse
- RESOURCE =
"/faculty/textbooks/"
Class Method Summary collapse
- .all ⇒ Array<Hash>
-
.get_html ⇒ String
Html.
- .process_html(html) ⇒ Array<Hash>
- .process_option(option) ⇒ Hash
- .process_title(title) ⇒ String
Class Method Details
.all ⇒ 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_html ⇒ String
Returns 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>
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
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
38 39 40 |
# File 'lib/osu-ctl-scraper/department.rb', line 38 def self.process_title(title) title.split(':')[1].strip end |