Class: Sites::WeWorkRemotely

Inherits:
Base
  • Object
show all
Defined in:
lib/sites/we_work_remotely.rb

Constant Summary collapse

HOST =
'https://weworkremotely.com'.freeze
PATH =
'/categories/remote-programming-jobs'.freeze
DEVOPS =
'/categories/remote-devops-sysadmin-jobs'.freeze
JOB_ITEM_SELECTOR =
'.jobs-container li a'.freeze
STORE_DIR =
'data/we_work_remotely'

Instance Attribute Summary

Attributes inherited from Base

#doc, #jobs_count, #rows_count, #url

Instance Method Summary collapse

Constructor Details

#initializeWeWorkRemotely

Returns a new instance of WeWorkRemotely.



12
13
14
# File 'lib/sites/we_work_remotely.rb', line 12

def initialize
  super
end

Instance Method Details

#collect_jobs(limit: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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