class Sites::WeWorkRemotely

Constants

DEVOPS
HOST
JOB_ITEM_SELECTOR
PATH
STORE_DIR

Public Class Methods

new() click to toggle source
Calls superclass method Sites::Base::new
# File lib/sites/we_work_remotely.rb, line 12
def initialize
  super
end

Public Instance Methods

collect_jobs(limit: nil) click to toggle source
# File lib/sites/we_work_remotely.rb, line 16
def collect_jobs(limit: nil)
  puts "[Info] Getting the data from #{url}"
  FileUtils.mkdir_p STORE_DIR

  CSV.open(filepath, 'w') do |csv|
    doc.css(JOB_ITEM_SELECTOR).each do |link|
      if link["href"].start_with?("/remote-jobs")
        return if limit == @rows_count

        job_url = "#{HOST}#{link["href"]}"
        puts "[Info] Parsing #{job_url}..."

        csv << get_row(job_url)

        @rows_count += 1
      end
    end
  end

  puts "[Done] Collected #{@rows_count} job offers from #{url}. Data stored in: #{filepath}."
end

Private Instance Methods

get_jobs_count() click to toggle source
# File lib/sites/we_work_remotely.rb, line 52
def get_jobs_count
  jobs_count = doc.css(JOB_ITEM_SELECTOR)
    .map { |link| link['href'] }
    .select { |href| href.start_with?('/remote-jobs') }
    .size
  puts "[Info] There are #{jobs_count} remote jobs on [WeWorkRemotely]."
  jobs_count
end
get_row(job_url) click to toggle source
# File lib/sites/we_work_remotely.rb, line 40
def get_row(job_url)
  job_page = Nokogiri::HTML(open_page(job_url))
  offer_text = job_page.css('.listing-container').to_s

  region = job_page.css('.listing-header-container span.region').first
  location = job_page.css('.listing-header-container span.location').first
  keywords = Support::OfferParser.get_keywords(offer_text)
  company = job_page.css('.listing-header-container span.company').first

  [job_url, location, region, keywords, company]
end