Class: Sites::GithubRemoteJobs

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

Constant Summary collapse

HOST =
'http://github.com/'.freeze
PATH =
'remoteintech/remote-jobs'
JOB_ITEM_SELECTOR =
'.entry-content table tbody tr'.freeze
STORE_DIR =
'data/github_remote_jobs'.freeze

Instance Attribute Summary

Attributes inherited from Base

#doc, #jobs_count, #rows_count, #url

Instance Method Summary collapse

Constructor Details

#initializeGithubRemoteJobs

Returns a new instance of GithubRemoteJobs.



9
10
11
12
13
14
15
# File 'lib/sites/github_remote_jobs.rb', line 9

def initialize()
  @url = "#{self.class::HOST}#{self.class::PATH}"
  @current_time = Time.now
  @timestamp = @current_time.strftime("%Y%m%d%H%M%S")
  @doc = Nokogiri::HTML(open_page(@url))
  @rows_count = 0
end

Instance Method Details

#collect_companiesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sites/github_remote_jobs.rb', line 17

def collect_companies
  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 |tr|
      name = tr.search('td')[0].text
      website = tr.search('td')[1].text
      region = tr.search('td')[2].text
      csv << [name, website, region]
      @rows_count += 1
    end
  end
  puts "[Done] Collected #{@rows_count} job offers from #{url}. Data stored in: #{filepath}."
end

#companies_countObject



33
34
35
# File 'lib/sites/github_remote_jobs.rb', line 33

def companies_count
  @rows_count
end