Module: CodeSchool
- Included in:
- SiteScraper
- Defined in:
- lib/code_school/version.rb,
lib/code_school/code_school.rb
Overview
Scraper for CodeSchool website
Constant Summary collapse
- VERSION =
'0.0.4'- DATE =
'2015-10-24'- COURSES =
'https://www.codeschool.com/courses'
Instance Method Summary collapse
-
#code_school_data ⇒ Object
JSON array of course names (string) and teacher(s) (array).
-
#course_names ⇒ Object
Get an array of course names.
-
#course_urls ⇒ Object
Change course names to urls.
-
#courses ⇒ Object
Gets array of courses.
-
#teacher(name) ⇒ Object
Gets names of teacher(s) for one course.
-
#teacher_names ⇒ Object
Get teachar’s name by visiting each course page.
Instance Method Details
#code_school_data ⇒ Object
JSON array of course names (string) and teacher(s) (array)
41 42 43 44 45 46 |
# File 'lib/code_school/code_school.rb', line 41 def code_school_data course_names.zip(teacher_names).map do |c_t| # { course: c_t[0], teacher: c_t[1] } { c_t[0] => c_t[1] } end.to_json end |
#course_names ⇒ Object
Get an array of course names
20 21 22 |
# File 'lib/code_school/code_school.rb', line 20 def course_names courses.xpath('//h2/a').map(&:text) end |
#course_urls ⇒ Object
Change course names to urls
25 26 27 28 29 30 31 |
# File 'lib/code_school/code_school.rb', line 25 def course_urls # Turn ' ', '.' to '-' # Delete ':' course_names.map do |name| name.downcase.split(' ').join('-').tr('.', '-').delete(':') end end |
#courses ⇒ Object
Gets array of courses
10 11 12 |
# File 'lib/code_school/code_school.rb', line 10 def courses Nokogiri::HTML(open(COURSES)) end |
#teacher(name) ⇒ Object
Gets names of teacher(s) for one course
15 16 17 |
# File 'lib/code_school/code_school.rb', line 15 def teacher(name) Nokogiri::HTML(open("#{COURSES}/#{name}")) end |
#teacher_names ⇒ Object
Get teachar’s name by visiting each course page
34 35 36 37 38 |
# File 'lib/code_school/code_school.rb', line 34 def teacher_names course_urls.map do |course_url| teacher(course_url).xpath('//h3/a').map(&:text) end end |