osu-cc-scraper 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71df7f91c3049b5d62323435cb066f324c2882ab
4
- data.tar.gz: 02eb25347ade8940adabd831f87cbd631c943f1b
3
+ metadata.gz: 49aea5047e818d92404a7f5b6d3dcbf1a987f65b
4
+ data.tar.gz: bec95b9ba989b16c91e4f12b614728bec9df8e06
5
5
  SHA512:
6
- metadata.gz: 1a2017bbf88c24da39b941bbd69bacc3a8cf5fe1309e28a530649bbac78de660a17d60b6b068e91e7d037f05950d28cd33e7f530b9765acc1ee4081c683061fd
7
- data.tar.gz: 9573bdcb5255459cdfda6072ec943d9001915ef6fc97860177fa0bd3358acd145bbb75335372d7f8267bad1bccbad60df247cc4fc32b399f41f4643d7657e127
6
+ metadata.gz: 4a49fdac45ab85eff7f81ae245d17d22832246eb7f804e32640d1311109fe3d8b6b1cb48ac1bc100da56bbb8cae6117669ff03fbdc88aba460cf23e62efbc0da
7
+ data.tar.gz: dfe8e6bbb90fae2d24c0a14dbb4cb33f0f5a8695b97b7233752756a16d5ac83a0880a6f081ffb9b3db51790c3ceea0809e5c9c517644a09f688e2d005d3bc779
@@ -1,10 +1,9 @@
1
1
  require "open-uri"
2
2
  require "oga"
3
-
4
3
  require "osu-cc-scraper/section"
5
4
 
6
5
  module OsuCcScraper
7
- class Course < Struct.new(:subject_code, :course_number, :name)
6
+ class Course < Struct.new(:department, :course_number, :name)
8
7
 
9
8
  def sections
10
9
  html = fetch_sections
@@ -17,23 +16,22 @@ module OsuCcScraper
17
16
  TITLE_XPATH = "//form/h3"
18
17
 
19
18
  def fetch_sections
20
- open("#{ENDPOINT}/CourseDetail.aspx?subjectcode=#{subject_code}&coursenumber=#{course_number}").read
19
+ open("#{ENDPOINT}/CourseDetail.aspx?subjectcode=#{department.subject_code}&coursenumber=#{course_number}").read
21
20
  end
22
21
 
23
22
  def parse_sections(html)
24
23
  document = Oga.parse_html(html)
25
24
 
26
- document.xpath(SECTIONS_XPATH).map { |row|
25
+ document.xpath(SECTIONS_XPATH).map { |row|
27
26
  Section.new(
28
- parse_department(document),
29
- parse_number(document),
30
- parse_name(document),
31
- parse_term(row),
27
+ self,
28
+ parse_term(row),
32
29
  parse_section(row),
33
- parse_instructor(row),
34
- parse_type(row),
30
+ parse_instructor(row),
31
+ parse_campus(row),
32
+ parse_type(row),
35
33
  parse_status(row),
36
- parse_capacity(row),
34
+ parse_capacity(row),
37
35
  parse_current(row)
38
36
  )
39
37
  }
@@ -43,21 +41,6 @@ module OsuCcScraper
43
41
  document.xpath(selector)&.text&.delete("\r\n")&.strip
44
42
  end
45
43
 
46
- def parse_department(document)
47
- title = document.xpath(TITLE_XPATH).text.split("\n")
48
- title[2].delete("\r\n").strip[0..-2].split(" ")[0]
49
- end
50
-
51
- def parse_number(document)
52
- title = document.xpath(TITLE_XPATH).text.split("\n")
53
- title[2].split(" ")[1][0..-2]
54
- end
55
-
56
- def parse_name(document)
57
- title = document.xpath(TITLE_XPATH).text.split("\n")
58
- title[3].strip
59
- end
60
-
61
44
  def parse_term(row)
62
45
  fetch_column(row, "td[position() = 1]")
63
46
  end
@@ -70,6 +53,10 @@ module OsuCcScraper
70
53
  fetch_column(row, "td[position() = 6]")
71
54
  end
72
55
 
56
+ def parse_campus(row)
57
+ fetch_column(row, "td[position() = 9]")
58
+ end
59
+
73
60
  def parse_type(row)
74
61
  fetch_column(row, "td[position() = 11]")
75
62
  end
@@ -1,10 +1,9 @@
1
1
  require "open-uri"
2
2
  require "oga"
3
-
4
3
  require "osu-cc-scraper/course"
5
4
 
6
5
  module OsuCcScraper
7
- class Department < Struct.new(:name, :subject_code)
6
+ class Department < Struct.new(:university, :name, :subject_code)
8
7
 
9
8
  def courses
10
9
  html = fetch_courses
@@ -14,14 +13,14 @@ module OsuCcScraper
14
13
  private
15
14
 
16
15
  def fetch_courses
17
- open("#{ENDPOINT}/CourseList.aspx?subjectcode=#{subject_code}&level=undergrad&campus=corvallis").read
16
+ open("#{ENDPOINT}/CourseList.aspx?subjectcode=#{subject_code}&level=#{university.level}").read
18
17
  end
19
18
 
20
19
  def parse_courses(html)
21
20
  document = Oga.parse_html(html)
22
21
  document.xpath("//tr//td//strong/a[last()]").map { |row|
23
22
  Course.new(
24
- parse_course_subject_code(row),
23
+ self,
25
24
  parse_course_course_number(row),
26
25
  parse_course_name(row)
27
26
  )
@@ -1,5 +1,10 @@
1
1
  module OsuCcScraper
2
- class Section < Struct.new(:department, :number, :name, :term, :section,
3
- :instructor, :type, :status, :capacity, :current)
2
+ class Section < Struct.new(:course, :term, :section, :instructor, :campus,
3
+ :type, :status, :capacity, :current)
4
+ def to_a
5
+ [ course.department.subject_code, course.course_number, course.name,
6
+ term, section, instructor, campus, type, status, capacity, current ]
7
+ end
8
+
4
9
  end
5
10
  end
@@ -1,37 +1,39 @@
1
1
  require "open-uri"
2
2
  require "oga"
3
-
4
3
  require "osu-cc-scraper/department"
5
4
 
6
5
  module OsuCcScraper
7
- class University
6
+ class University < Struct.new(:level)
8
7
 
9
8
  def departments
10
9
  html = fetch_departments
11
10
  parse_departments(html)
12
11
  end
13
12
 
14
- def fetch_departments
15
- open("#{ENDPOINT}/CourseDescription.aspx?level=undergrad").read
16
- end
17
-
18
- def parse_departments(html)
19
- ng = Oga.parse_html(html)
20
- ng.xpath("//tr/td/font/a").map { |row|
21
- Department.new(
22
- parse_department_name(row),
23
- parse_department_subject_code(row),
24
- )
25
- }
26
- end
27
-
28
- def parse_department_subject_code(row)
29
- row.text[/\(.*?\)/][1..-2]
30
- end
31
-
32
- def parse_department_name(row)
33
- row.text[/([^(]+)/].strip
34
- end
13
+ private
14
+
15
+ def fetch_departments
16
+ open("#{ENDPOINT}/CourseDescription.aspx?level=#{level}").read
17
+ end
18
+
19
+ def parse_departments(html)
20
+ ng = Oga.parse_html(html)
21
+ ng.xpath("//tr/td/font/a").map { |row|
22
+ Department.new(
23
+ self,
24
+ parse_department_name(row),
25
+ parse_department_subject_code(row),
26
+ )
27
+ }
28
+ end
29
+
30
+ def parse_department_subject_code(row)
31
+ row.text[/\(.*?\)/][1..-2]
32
+ end
33
+
34
+ def parse_department_name(row)
35
+ row.text[/([^(]+)/].strip
36
+ end
35
37
 
36
38
  end
37
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osu-cc-scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonah George
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-20 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga