lse_courses 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +48 -0
- data/lib/lse_courses/course.rb +132 -0
- data/lib/lse_courses/survey_result.rb +10 -0
- data/lib/lse_courses/version.rb +3 -0
- data/lib/lse_courses.rb +3 -0
- data/lse_courses.gemspec +22 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86c640247013f44f18ba17e7abc6fa037e498e44
|
4
|
+
data.tar.gz: acd3967aac16df1b85f268cb092c34bf8b7bf58a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 553d717bfbf3cf480786afcd364c41d65d421335933bb7f0697ddfbd908dbff4a0014668b81bc7efee4bbfce77f13d7711ef7e2b565ea4edee898c70cd1de656
|
7
|
+
data.tar.gz: a906cc99a9718f5545ba6bec3a2fa859b0170c31efc5536de711745c5af84ec2aa22d8c6d547c6b492bb11ee31808b9f724fbb669997685bbd374bef1c7c2dfd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Tim Rogers
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# LSE Courses
|
2
|
+
|
3
|
+
A gem for accessing course data from the [London School of Economics](http://lse.ac.uk)'s [Calendar](http://www.lse.ac.uk/resources/calendar/).
|
4
|
+
|
5
|
+
I'm planning to use this for a project, but I'm not 100% sure what yet - perhaps
|
6
|
+
something along the line of [YalePlus](http://yaleplus.com/)'s Bluebook+.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
Add the gem to your Gemfile, then run `bundle install`:
|
11
|
+
|
12
|
+
```
|
13
|
+
gem 'lse_courses', git: 'git@github.com:timrogers/lse_courses.git'
|
14
|
+
```
|
15
|
+
|
16
|
+
You might need to add a call to `require 'lse_courses'` in your code,
|
17
|
+
dependent on your setup.
|
18
|
+
|
19
|
+
You can retrieve an array with every course offered at LSE:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
courses = LSECourses::Course.all
|
23
|
+
courses.each do |course|
|
24
|
+
puts "#{course.code} - #{course.name}"
|
25
|
+
|
26
|
+
# LSE records include surveys on courses - stored in #survey on the object
|
27
|
+
puts "#{course.survey.recommended_by}% of students recommend this cause"
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
...or you can fetch a specific course by code:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
course = LSECourses::Course.find_by_code("LSE100")
|
35
|
+
puts course.name
|
36
|
+
```
|
37
|
+
|
38
|
+
Upcoming features that should be added are some kind of search (e.g. for
|
39
|
+
finding a course by name) and a way to find courses by type (e.g. undergraduate, graduate)...
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new pull request
|
48
|
+
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'active_support/core_ext/object/try'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module LSECourses
|
5
|
+
class Course
|
6
|
+
attr_reader :code, :name, :department, :students, :average_class_size,
|
7
|
+
:value, :assessments, :teachers, :availability, :prerequisites,
|
8
|
+
:content, :teaching, :formative_coursework, :reading, :type, :survey
|
9
|
+
|
10
|
+
def initialize(opts = {})
|
11
|
+
opts.each { |k, v| instance_variable_set("@#{k}", v) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def undergraduate?
|
15
|
+
type == "Undergraduate"
|
16
|
+
end
|
17
|
+
|
18
|
+
def graduate?
|
19
|
+
type == "Graduate"
|
20
|
+
end
|
21
|
+
|
22
|
+
def research?
|
23
|
+
type == "Research"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Checks if this module is available to General Course students
|
27
|
+
def general_course?
|
28
|
+
general_course_list = open("http://www.lse.ac.uk/resources/calendar/GeneralCourse/coursesNotAvailableToGeneralCStudents.htm")
|
29
|
+
!general_course_list.read.include? code
|
30
|
+
end
|
31
|
+
|
32
|
+
def survey?
|
33
|
+
!!survey
|
34
|
+
end
|
35
|
+
|
36
|
+
alias_method :available_on_general_course?, :general_course?
|
37
|
+
alias_method :title, :name
|
38
|
+
|
39
|
+
# Class methods
|
40
|
+
def self.course_lists
|
41
|
+
{
|
42
|
+
"Undergraduate" => "http://www.lse.ac.uk/resources/calendar/courseGuides/undergraduate.htm",
|
43
|
+
"Graduate" => "http://www.lse.ac.uk/resources/calendar/courseGuides/graduate.htm",
|
44
|
+
"Research" => "http://www.lse.ac.uk/resources/calendar/courseGuides/research.htm"
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.all
|
49
|
+
results = []
|
50
|
+
|
51
|
+
course_lists.each_pair do |type, url|
|
52
|
+
document = fetch_and_parse(url)
|
53
|
+
document.css('table tr td p a').each do |link|
|
54
|
+
course_url = URI.join(URI.parse(url), URI.parse(link['href'])).to_s
|
55
|
+
|
56
|
+
course = fetch_and_parse course_url
|
57
|
+
key_facts = course.css('#keyFacts-Content p')
|
58
|
+
code = course.css('#courseCode').text
|
59
|
+
|
60
|
+
results << course_page_to_object(course, type)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
results
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.find_by_code(code)
|
68
|
+
course_lists.each_pair do |type, url|
|
69
|
+
document = fetch_and_parse(url)
|
70
|
+
document.css('table tr td p a').each do |link|
|
71
|
+
title = link.text
|
72
|
+
course_code = title.split(" ").first
|
73
|
+
|
74
|
+
if code == course_code
|
75
|
+
course = fetch_and_parse(
|
76
|
+
URI.join(URI.parse(url), URI.parse(link['href'])).to_s
|
77
|
+
)
|
78
|
+
|
79
|
+
return course_page_to_object(course, type)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.course_page_to_object(page, type)
|
88
|
+
key_facts = page.css('#keyFacts-Content p')
|
89
|
+
|
90
|
+
survey_result = if page.css('#survey-Label').any?
|
91
|
+
SurveyResult.new(
|
92
|
+
response_rate: page.css('#survey-Label-2 span').text.gsub("Response rate: ", "").gsub("%", "").to_f,
|
93
|
+
recommended_by: page.css('#survey-Content-Recommend p')[1].text.gsub("%", "").to_f,
|
94
|
+
reading_list: page.css('#survey-Content table tbody td')[1].text.to_f,
|
95
|
+
materials: page.css('#survey-Content table tbody td')[3].text.to_f,
|
96
|
+
satisfied: page.css('#survey-Content table tbody td')[5].text.to_f,
|
97
|
+
lectures: page.css('#survey-Content table tbody td')[7].text.to_f,
|
98
|
+
integration: page.css('#survey-Content table tbody td')[9].text.to_f,
|
99
|
+
contact: page.css('#survey-Content table tbody td')[11].text.to_f,
|
100
|
+
feedback: page.css('#survey-Content table tbody td')[13].text.to_f,
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
self.new(
|
105
|
+
type: type,
|
106
|
+
code: page.css('#courseCode').text,
|
107
|
+
name: page.css('span#title').text,
|
108
|
+
department: key_facts[0].text.gsub("Department: ", ""),
|
109
|
+
students: key_facts[1].text.gsub("Total students 2012/13:", "").to_i,
|
110
|
+
average_class_size: key_facts[2].text.gsub("Average class size 2012/13: ", "").to_i,
|
111
|
+
value: key_facts[3].text.gsub("Value: ", ""),
|
112
|
+
assessments: join_p_tags(page.css('#assessment-Content p')),
|
113
|
+
teachers: join_p_tags(page.css('#teacherResponsible-Content p')),
|
114
|
+
availability: join_p_tags(page.css('#availability-Content p')),
|
115
|
+
prerequisites: join_p_tags(page.css('#preRequisites-Content p')),
|
116
|
+
content: join_p_tags(page.css('#courseContent-Content p')),
|
117
|
+
teaching: join_p_tags(page.css('#teaching-Content p')),
|
118
|
+
formative_coursework: join_p_tags(page.css('#formativeCoursework-Content p')),
|
119
|
+
reading: join_p_tags(page.css('#indicativeReading-Content p')),
|
120
|
+
survey: survey_result
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.join_p_tags(elements)
|
125
|
+
elements.map(&:text).join("\n").strip
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.fetch_and_parse(url)
|
129
|
+
Nokogiri::HTML(open(url, &:read), 'UTF-8')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module LSECourses
|
2
|
+
class SurveyResult
|
3
|
+
attr_reader :response_rate, :recommended_by, :reading_list, :materials,
|
4
|
+
:satisfied, :lectures, :integration, :contact, :feedback
|
5
|
+
|
6
|
+
def initialize(opts = {})
|
7
|
+
opts.each { |k, v| instance_variable_set("@#{k}", v) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/lse_courses.rb
ADDED
data/lse_courses.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lse_courses/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lse_courses"
|
8
|
+
spec.version = LSECourses::VERSION
|
9
|
+
spec.summary = %Q{Access to data on courses at the London School of Economics and Political Science (LSE)}
|
10
|
+
spec.authors = ["Tim Rogers"]
|
11
|
+
spec.email = ["t.d.rogers@lse.ac.uk"]
|
12
|
+
spec.description = %Q{Access to data on courses at the London School of Economics and Political Science (LSE)}
|
13
|
+
spec.homepage = "https://github.com/timrogers/lse_courses"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "nokogiri"
|
21
|
+
spec.add_runtime_dependency "activesupport"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lse_courses
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Rogers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Access to data on courses at the London School of Economics and Political
|
42
|
+
Science (LSE)
|
43
|
+
email:
|
44
|
+
- t.d.rogers@lse.ac.uk
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- lib/lse_courses.rb
|
54
|
+
- lib/lse_courses/course.rb
|
55
|
+
- lib/lse_courses/survey_result.rb
|
56
|
+
- lib/lse_courses/version.rb
|
57
|
+
- lse_courses.gemspec
|
58
|
+
homepage: https://github.com/timrogers/lse_courses
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.3
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Access to data on courses at the London School of Economics and Political
|
81
|
+
Science (LSE)
|
82
|
+
test_files: []
|