remote_job_scraper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ require 'spreadsheet'
2
+
3
+ module Support
4
+ module SpreadsheetCreator
5
+
6
+ def self.generate(path: 'data/summary/', filename: 'remote_job_summary_.xls')
7
+ Spreadsheet.client_encoding = 'UTF-8'
8
+ book = Spreadsheet::Workbook.new
9
+
10
+ dirnames.each_with_index do |dirname, index|
11
+ file = Dir.glob(dirname).first
12
+ sheet = book.create_worksheet name: dirname.split("/")[-2]
13
+
14
+ CSV.foreach(file).with_index(0) do |row, index|
15
+ sheet.row(index).push(*(Spreadsheet::Link.new row[0]), *row[1..-1])
16
+ end
17
+ end
18
+
19
+ book.write path.concat(
20
+ Time.now.strftime("%Y%m%d%H%M%S").concat('_remote_jobs_summary.xls')
21
+ )
22
+ end
23
+
24
+ def self.dirnames
25
+ if ENV['RAILS_ENV'] == 'test'
26
+ [
27
+ "#{RemoteJobScraper.root}/spec/fixtures/data/remote_ok/*",
28
+ "#{RemoteJobScraper.root}/spec/fixtures/data/we_work_remotely/*",
29
+ "#{RemoteJobScraper.root}/spec/fixtures/data/jobs_rails42/*"
30
+ ]
31
+ else
32
+ [
33
+ "#{RemoteJobScraper.root}/data/remote_ok/*",
34
+ "#{RemoteJobScraper.root}/data/we_work_remotely/*",
35
+ "#{RemoteJobScraper.root}/data/jobs_rails42/*"
36
+ ]
37
+ end
38
+ end
39
+ end
40
+ end