This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Scraper | |
| require 'nokogiri' | |
| require 'open-uri' | |
| attr_accessor :source, :index_url, :index_doc, :job_url_collection, :base_url_for_job, :job_database | |
| def initialize(source, index_url, base_url_for_job, job_database) | |
| @source = source | |
| @index_url = index_url | |
| @base_url_for_job = base_url_for_job |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def self.save_record(student) | |
| record = Marshal.dump(student) | |
| db_connection.execute('INSERT INTO students (student) VALUES (?);', [record]) | |
| end | |
| def self.update_record(student) | |
| id = student.id | |
| row = Marshal.dump(student) | |
| db_connection.execute('UPDATE students SET student = ? WHERE id = ?', [row, id]) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def scrape_away(args) | |
| threads = [] | |
| self.job_url_collection.each do |job_url| | |
| threads << Thread.new do | |
| job_doc = Nokogiri::HTML(open(job_url)) | |
| title = job_doc.css(args[:title_selector]).inner_text.strip | |
| company = job_doc.css(args[:company_selector]).inner_text.strip | |
| source = self.source | |
| job_url = job_url.strip | |
| location = job_doc.css(args[:location_selector]).inner_text.strip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def assert_equal(actual, expected) | |
| if expected == actual | |
| puts 'pass' | |
| else | |
| puts "fail: expected #{expected}, got #{actual}" | |
| end | |
| end | |
| def assert(statement) | |
| if statement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AuthenticationsController < ApplicationController | |
| def create | |
| omniauth = auth_hash | |
| authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid']) | |
| if authentication | |
| sign_in(authentication.user) | |
| redirect_to root_url, notice: "Signed in!" | |
| else | |
| sign_in(User.create_from_omniauth(omniauth)) if current_user.blank? |
NewerOlder