Class: JobsChaser
- Inherits:
-
Object
- Object
- JobsChaser
- Defined in:
- lib/jobs_chaser.rb
Instance Method Summary collapse
- #execute ⇒ Object
- #export(csv_filename, offers) ⇒ Object
-
#initialize(title_keywords_file, description_keywords_file) ⇒ JobsChaser
constructor
A new instance of JobsChaser.
- #select_api_client(site_name) ⇒ Object
Constructor Details
#initialize(title_keywords_file, description_keywords_file) ⇒ JobsChaser
Returns a new instance of JobsChaser.
9 10 11 12 13 14 |
# File 'lib/jobs_chaser.rb', line 9 def initialize(title_keywords_file, description_keywords_file) config_path = File.join(__dir__, '..', 'config', 'sites.yml') @sites = YAML.load_file(config_path) @title_keywords_file = title_keywords_file @description_keywords_file = description_keywords_file end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jobs_chaser.rb', line 16 def execute job_list = [] @sites.each do |key, val| puts "Getting offers for: #{key}" client = select_api_client(key) data = client.fetch_jobs(val['url']) job_list.concat(data[val['json_key']] || []) end job_list = JobFilter.discard(job_list, @title_keywords_file) valid_jobs = JobFilter.filter_jobs(job_list, @description_keywords_file) export(csv_filename, valid_jobs) end |
#export(csv_filename, offers) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jobs_chaser.rb', line 43 def export(csv_filename, offers) if defined?(Rails) # Running in a Rails project rails_root = Rails.root else # Running outside a Rails project, use a fallback directory rails_root = Pathname.new(__FILE__).dirname.dirname end output_path = rails_root.join('data', csv_filename) CSV.open(output_path, 'w') do |csv| csv << ['Date', 'Job Title', 'Company', 'Location', 'URL'] offers.each { |offer| csv << [Date.today, offer[:title], offer[:company], offer[:location], offer[:url]] } end puts "Job offers have been exported and saved to #{output_path}." end |
#select_api_client(site_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jobs_chaser.rb', line 32 def select_api_client(site_name) case site_name when 'Remotive - Software Dev Jobs', 'Remotive - Ruby Jobs', 'Remotive - Ruby on Rails Jobs' RemotiveClient.new when 'GetOnBrd - Ruby Jobs', 'GetOnBrd - Ruby on Rails Jobs', 'GetOnBrd - Python Jobs', 'GetOnBrd - Software Engineer Jobs' GetOnBrdClient.new else raise "Unsupported site: #{site_name}" end end |