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.5'
- DATE =
'2015-10-24'
- COURSES =
'https://www.codeschool.com/courses'
- COURSE_NAMES_XPATH =
'//h2/a'
- TEACHER_NAMES_XPATH =
'//h3/a'
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)
43 44 45 46 47 48 |
# File 'lib/code_school/code_school.rb', line 43 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
22 23 24 |
# File 'lib/code_school/code_school.rb', line 22 def course_names courses.xpath(COURSE_NAMES_XPATH).map(&:text) end |
#course_urls ⇒ Object
Change course names to urls
27 28 29 30 31 32 33 |
# File 'lib/code_school/code_school.rb', line 27 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
12 13 14 |
# File 'lib/code_school/code_school.rb', line 12 def courses Nokogiri::HTML(open(COURSES)) end |
#teacher(name) ⇒ Object
Gets names of teacher(s) for one course
17 18 19 |
# File 'lib/code_school/code_school.rb', line 17 def teacher(name) Nokogiri::HTML(open("#{COURSES}/#{name}")) end |
#teacher_names ⇒ Object
Get teachar’s name by visiting each course page
36 37 38 39 40 |
# File 'lib/code_school/code_school.rb', line 36 def teacher_names course_urls.map do |course_url| teacher(course_url).xpath(TEACHER_NAMES_XPATH).map(&:text) end end |