show-job 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/show-job +145 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b1a24099b1c214d84633b59ddc83c1eaca9261f623f428342187a93a14d735ca
4
+ data.tar.gz: 7b9e493b5f8e572ad6b5cd9ae44428d722c90374165956827a4b42ed32421056
5
+ SHA512:
6
+ metadata.gz: 795a9a9fa2b6c9d0b131bc4aaa62f4a67c1d16d5a3d912f47b34ba6cbb7d2712df88a28b2ab1bda381ba33b20161f62d67558c93ffc22c44cbb81d3c53cbca11
7
+ data.tar.gz: 925177e4fd56f7577f966fc7ff2ca4253791b42ff5aadb7bb5278628f1965694f66d0a7dabac1b697cd3957efeee8c49209ce076ea831babcf46892ccfab8216
data/bin/show-job ADDED
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'tempfile'
4
+ require 'json'
5
+ require 'open-uri'
6
+ require 'debug'
7
+
8
+ class String
9
+ def red
10
+ colorize(31)
11
+ end
12
+
13
+ def light_blue
14
+ colorize(36)
15
+ end
16
+
17
+ private
18
+
19
+ def colorize(color_code)
20
+ "\e[#{color_code}m#{self}\e[0m"
21
+ end
22
+
23
+ end
24
+
25
+ # A bug is that
26
+ # --ww + --senior should show results
27
+ # that are worldwide openings for seniors.
28
+ # Currently --ww + --senior will show
29
+ # [ww jobs] + [senior jobs].
30
+ # The regex should change.
31
+ # It should be looking for both (senior|world)
32
+ #
33
+ # This could not be a bug and
34
+ # I might just be thinking too much.
35
+ class ShowJob
36
+ attr_reader :jobs
37
+
38
+ def initialize
39
+ @parser = OptionParser.new
40
+ @jobs = []
41
+ @fetched_jobs = JSON.parse URI.open('http://www.rubyyeast.com/jobs.json').read
42
+ end
43
+
44
+ def show
45
+ add_ww_jobs
46
+ add_senior_jobs
47
+ add_us_only_jobs
48
+ add_no_us_jobs
49
+ if ARGV.empty?
50
+ puts @parser.help
51
+ exit
52
+ end
53
+ @parser.parse!
54
+ show_jobs
55
+ end
56
+
57
+ private
58
+
59
+ # Add support for non-senior jobs
60
+ # non senior jobs donot contain the word senior in there
61
+ def add_senior_jobs
62
+ @parser.on('--senior', 'Display only senior jobs') do |value|
63
+ @jobs = @jobs + search_for('senior')
64
+ end
65
+ end
66
+
67
+ # non ww jobs donot contain the word 'world'
68
+ # donot_search_for('world')
69
+ def add_ww_jobs
70
+ @parser.on('--ww', 'Display only worldwide jobs') do |value|
71
+ @jobs = @jobs + search_for('world')
72
+ end
73
+ end
74
+
75
+ def add_us_only_jobs
76
+ @parser.on('--us-only', 'Display jobs only for the United States') do |value|
77
+ @jobs = @jobs + us_search
78
+ end
79
+ end
80
+
81
+ def add_no_us_jobs
82
+ @parser.on('--no-us', 'Display jobs for places other than United States') do |value|
83
+ @jobs = @jobs + non_us_search
84
+ end
85
+ end
86
+
87
+ def search_for(str)
88
+ result = []
89
+ @fetched_jobs.each do |arr_of_hash|
90
+ result << arr_of_hash.select do |job|
91
+ job["title"].match?(/#{str}/i) || job["misc"].match?(/#{str}/i)
92
+ end
93
+ end
94
+ result.flatten
95
+ end
96
+
97
+ def us_search
98
+ result = []
99
+ str = 'US|United States'
100
+ @fetched_jobs.each do |arr_of_hash|
101
+ result << arr_of_hash.select do |job|
102
+ job["title"].match?(/#{str}/) || job["misc"].match?(/#{str}/)
103
+ end
104
+ end
105
+ result.flatten
106
+ end
107
+
108
+ def non_us_search
109
+ result = []
110
+ str = 'US|United States'
111
+ @fetched_jobs.each do |arr_of_hash|
112
+ result << arr_of_hash.reject do |job|
113
+ job["title"].match?(/#{str}/) || job["misc"].match?(/#{str}/)
114
+ end
115
+ end
116
+ result.flatten
117
+ end
118
+
119
+ def show_jobs
120
+ file = Tempfile.new
121
+ file.write prettify
122
+ file.close
123
+ system("less -R #{file.path}")
124
+ file.unlink
125
+ end
126
+
127
+ def prettify
128
+ result = "\n"
129
+ jobs.uniq.each do |job|
130
+ # remoteonruby job titles have a newline in them
131
+ # which causes the colors to break when displaying.
132
+ # This is why I am removing the newline here.
133
+ str = job['title'].gsub("\n", "").red + "\n" + remove_whitespace(job['misc'].light_blue) + "\n" + job['href'] + "\n"
134
+ result << str
135
+ result << "-------------------------\n\n"
136
+ end
137
+ result + "Created by avi (avii@hey.com)"
138
+ end
139
+
140
+ def remove_whitespace(str)
141
+ str.split(" ").join(' ')
142
+ end
143
+ end
144
+
145
+ ShowJob.new.show
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: show-job
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Avi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Shows jobs fetched from different ruby job sites
14
+ email: avii@hey.com
15
+ executables:
16
+ - show-job
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/show-job
21
+ homepage: https://rubygems.org/gems/show-job
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.4.17
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Shows jobs fetched from different ruby job sites
44
+ test_files: []