osu-cc-scraper 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49aea5047e818d92404a7f5b6d3dcbf1a987f65b
4
- data.tar.gz: bec95b9ba989b16c91e4f12b614728bec9df8e06
3
+ metadata.gz: 8a7c8e0f916fd670730f4f80e45f2742512420df
4
+ data.tar.gz: e7d63ba37d98faf404e5c72ac14c100908b7b060
5
5
  SHA512:
6
- metadata.gz: 4a49fdac45ab85eff7f81ae245d17d22832246eb7f804e32640d1311109fe3d8b6b1cb48ac1bc100da56bbb8cae6117669ff03fbdc88aba460cf23e62efbc0da
7
- data.tar.gz: dfe8e6bbb90fae2d24c0a14dbb4cb33f0f5a8695b97b7233752756a16d5ac83a0880a6f081ffb9b3db51790c3ceea0809e5c9c517644a09f688e2d005d3bc779
6
+ metadata.gz: 2f3e0c2432c9adb001fea9c19733fd0b07b29aad6c75baf858f05170a6449c6b7f627352bc23844df1029a13173693ec951f3f2c72c7eb0a2f6a18baf6cc1e16
7
+ data.tar.gz: 2d27785cd4bf5e2f9893f44cf00dd1c77747bf2992f348990b8de6de592539f664ec3f4222445176897c87c6691dde944c7b3cdd1a95842cad9232ec9ec105ac
@@ -1,22 +1,31 @@
1
1
  require "open-uri"
2
2
  require "oga"
3
3
  require "osu-cc-scraper/section"
4
+ require "json"
4
5
 
5
6
  module OsuCcScraper
6
- class Course < Struct.new(:department, :course_number, :name)
7
+ class Course < Struct.new(:subject_code, :course_number, :name)
7
8
 
8
9
  def sections
9
10
  html = fetch_sections
10
11
  parse_sections(html)
11
12
  end
12
13
 
14
+ def to_json
15
+ self.to_h.to_json
16
+ end
17
+
18
+ def self.from_json(json)
19
+ Course.new(*JSON.parse(json).values)
20
+ end
21
+
13
22
  private
14
23
 
15
24
  SECTIONS_XPATH = "//table[@id='ctl00_ContentPlaceHolder1_SOCListUC1_gvOfferings']//tr[position() > 1]"
16
25
  TITLE_XPATH = "//form/h3"
17
26
 
18
27
  def fetch_sections
19
- open("#{ENDPOINT}/CourseDetail.aspx?subjectcode=#{department.subject_code}&coursenumber=#{course_number}").read
28
+ open("#{ENDPOINT}/CourseDetail.aspx?subjectcode=#{subject_code}&coursenumber=#{course_number}").read
20
29
  end
21
30
 
22
31
  def parse_sections(html)
@@ -24,7 +33,9 @@ module OsuCcScraper
24
33
 
25
34
  document.xpath(SECTIONS_XPATH).map { |row|
26
35
  Section.new(
27
- self,
36
+ subject_code,
37
+ course_number,
38
+ name,
28
39
  parse_term(row),
29
40
  parse_section(row),
30
41
  parse_instructor(row),
@@ -1,26 +1,35 @@
1
1
  require "open-uri"
2
2
  require "oga"
3
3
  require "osu-cc-scraper/course"
4
+ require "json"
4
5
 
5
6
  module OsuCcScraper
6
- class Department < Struct.new(:university, :name, :subject_code)
7
+ class Department < Struct.new(:name, :subject_code)
7
8
 
8
9
  def courses
9
10
  html = fetch_courses
10
11
  parse_courses(html)
11
12
  end
12
13
 
14
+ def to_json
15
+ self.to_h.to_json
16
+ end
17
+
18
+ def self.from_json(json)
19
+ Department.new(*JSON.parse(json).values)
20
+ end
21
+
13
22
  private
14
23
 
15
24
  def fetch_courses
16
- open("#{ENDPOINT}/CourseList.aspx?subjectcode=#{subject_code}&level=#{university.level}").read
25
+ open("#{ENDPOINT}/CourseList.aspx?subjectcode=#{subject_code}").read
17
26
  end
18
27
 
19
28
  def parse_courses(html)
20
29
  document = Oga.parse_html(html)
21
30
  document.xpath("//tr//td//strong/a[last()]").map { |row|
22
31
  Course.new(
23
- self,
32
+ subject_code,
24
33
  parse_course_course_number(row),
25
34
  parse_course_name(row)
26
35
  )
@@ -1,10 +1,6 @@
1
1
  module OsuCcScraper
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
-
2
+ class Section < Struct.new(:subject_code, :course_number, :name, :term,
3
+ :section, :instructor, :campus, :type, :status,
4
+ :capacity, :current)
9
5
  end
10
6
  end
@@ -3,7 +3,7 @@ require "oga"
3
3
  require "osu-cc-scraper/department"
4
4
 
5
5
  module OsuCcScraper
6
- class University < Struct.new(:level)
6
+ class University
7
7
 
8
8
  def departments
9
9
  html = fetch_departments
@@ -13,14 +13,13 @@ module OsuCcScraper
13
13
  private
14
14
 
15
15
  def fetch_departments
16
- open("#{ENDPOINT}/CourseDescription.aspx?level=#{level}").read
16
+ open("#{ENDPOINT}/CourseDescription.aspx").read
17
17
  end
18
18
 
19
19
  def parse_departments(html)
20
20
  ng = Oga.parse_html(html)
21
21
  ng.xpath("//tr/td/font/a").map { |row|
22
22
  Department.new(
23
- self,
24
23
  parse_department_name(row),
25
24
  parse_department_subject_code(row),
26
25
  )
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: 3.0.0
4
+ version: 4.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-03-02 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga