Class: DigitalNomadJobs::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/digital_nomad_jobs/cli.rb

Constant Summary collapse

PATH =
('https://remoteok.io')

Instance Method Summary collapse

Instance Method Details

#add_descriptions_to_jobsObject



197
198
199
200
201
202
# File 'lib/digital_nomad_jobs/cli.rb', line 197

def add_descriptions_to_jobs
  DigitalNomadJobs::Job.all.each do |job|
  description_hash = DigitalNomadJobs::Scraper.scrape_descriptions(PATH + job.job_url)
  job.add_job_description(description_hash)
  end 
end

#callObject



5
6
7
8
# File 'lib/digital_nomad_jobs/cli.rb', line 5

def call 
  welcome 
  main_menu
end

#display_companiesObject

——————————– CLI DISPLAY METHODS —————————–#



206
207
208
209
# File 'lib/digital_nomad_jobs/cli.rb', line 206

def display_companies
  DigitalNomadJobs::Company.list_companies
  select_company 
end

#display_jobsObject



212
213
214
215
# File 'lib/digital_nomad_jobs/cli.rb', line 212

def display_jobs
  DigitalNomadJobs::Job.list_all_jobs
  select_job 
end

#errorObject



150
151
152
# File 'lib/digital_nomad_jobs/cli.rb', line 150

def error
  puts 'Whoops! Please Enter A Valid Option.'.magenta 
end

#list_menuObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/digital_nomad_jobs/cli.rb', line 36

def list_menu
  puts "===========     LIST MENU    ===================".blue 
  puts ""
  puts "Enter '1' For A List of The Most Recent Job Postings"
  puts "Enter '2' For A List of The Companies Hiring"
  puts "Enter '0' To Exit"
  puts "Enter 'Main' To Go Back To The Main Menu"
  puts "================================================".blue 
  user_input = gets.strip.to_s

  case user_input 
  when '1'
    display_jobs
  when '2'
    display_companies 
  when 'Main', 'main'
    main_menu
  when '0', 'exit'
    puts "Thanks for Visiting!"
    exit 
  else 
    error
    list_menu
  end 
end


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/digital_nomad_jobs/cli.rb', line 20

def main_menu
  puts ""
  puts "========     🌎    MAIN MENU    🌎     ===========".blue 
  puts "                                                ".blue 
  puts "            What Are You Looking For?".blue 
  puts ""
  puts "Enter '1' for The Latest Web Developer Jobs" 
  puts "Enter '2' for The Latest UX/UI & Web Design Jobs" 
  puts "Enter '3' for The Latest Remote Jobs"
  puts "Enter '0' or type 'exit' to exit"
  puts ""
  puts "=========       x x x x x x x      =============".blue 
  select_job_maker 
end

#make_all_the_jobsObject



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/digital_nomad_jobs/cli.rb', line 183

def make_all_the_jobs
  DigitalNomadJobs::Job.reset
  DigitalNomadJobs::Company.reset
  job_array = DigitalNomadJobs::Scraper.scrape_jobs(PATH)
  DigitalNomadJobs::Job.create_from_collection(job_array)
  puts ""
  puts "                      🌎 " 
  puts "------------------------------------------------".blue 
  puts "         NABBING THE NEWEST REMOTE JOBS         ".white.on_blue 
  add_descriptions_to_jobs
  list_menu 
end

#make_design_jobsObject



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/digital_nomad_jobs/cli.rb', line 169

def make_design_jobs
  DigitalNomadJobs::Job.reset
  DigitalNomadJobs::Company.reset
  job_array = DigitalNomadJobs::Scraper.scrape_jobs(PATH + '/remote-design-jobs')
  DigitalNomadJobs::Job.create_from_collection(job_array)
  puts ""
  puts "                     🎨 " 
  puts "------------------------------------------------".blue 
  puts "           LOADING WEB DESIGN JOBS              ".white.on_blue 
  add_descriptions_to_jobs
  list_menu
end

#make_dev_jobsObject

———————————— CLI JOB FACTORY ————————————–#



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/digital_nomad_jobs/cli.rb', line 155

def make_dev_jobs
  DigitalNomadJobs::Job.reset
  DigitalNomadJobs::Company.reset
  job_array = DigitalNomadJobs::Scraper.scrape_jobs(PATH + '/remote-dev-jobs')
  DigitalNomadJobs::Job.create_from_collection(job_array)
  puts ""
  puts '                      🖥️                        '
  puts "------------------------------------------------".blue 
  puts "           NABBING WEB DEVELOPER JOBS           ".white.on_blue 
  add_descriptions_to_jobs
  list_menu
end


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/digital_nomad_jobs/cli.rb', line 63

def navigation
  puts ""
  puts "========         NAVIGATION          ===========".blue                                              
  puts "              Where Ya Headed Now?".blue     
  puts ""
  puts "Enter 'Main' to go Back to the Main Menu"
  puts "Enter 'List' To Go Back to the List Menu"
  puts "Enter 'Exit' to Exit."
  puts "=========       x x x x x x x      =============".blue
  puts ""
  input = gets.strip.to_s

  case input 
  when 'main', 'Main'
    main_menu
  when 'list', 'List'
    list_menu
  when 'exit', 'Exit'
    exit 
  else 
    puts 'Not All Those Who Wander Are Lost... But You Might Be!'.cyan 
    error 
    navigation   
  end
end

#select_companyObject



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/digital_nomad_jobs/cli.rb', line 110

def select_company
  puts ""
  puts "Enter The Number of A Company To See It's Recent Job Posts" 
  cn = gets.strip.to_i    
  if valid_company?(cn) 
    comp = DigitalNomadJobs::Company.all[cn-1]
    comp.print_company_jobs
    navigation 
  else 
    error
    select_company 
  end 
end

#select_jobObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/digital_nomad_jobs/cli.rb', line 135

def select_job
  puts ""
  puts "Enter The Number of a Job Post For a Detailed Description"
  jp = gets.strip.to_i

  if valid_job?(jp)
    job = DigitalNomadJobs::Job.all[jp - 1]
    job.print_job_description
    navigation 
  else 
    error 
    select_job
  end 
end

#select_job_makerObject

———————————- CLI INPUT SELECTORS ———————————-#



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/digital_nomad_jobs/cli.rb', line 91

def select_job_maker
  input = gets.strip.to_s
  case input
  when '1'
    make_dev_jobs
  when '2'
    make_design_jobs
  when '3'
    make_all_the_jobs
  when '0','exit'
    puts "Bye!".blue 
    exit 
  else 
    puts "Whoops! Please enter a valid option.".magenta 
    main_menu
  end
end

#valid_company?(input) ⇒ Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/digital_nomad_jobs/cli.rb', line 125

def valid_company?(input)
  input.between?(1, DigitalNomadJobs::Company.all.size)
end

#valid_job?(input) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/digital_nomad_jobs/cli.rb', line 130

def valid_job?(input)
  input.between?(1, DigitalNomadJobs::Job.all.size)
end

#welcomeObject

———————————- CLI MENUS ———————————-#



12
13
14
15
16
17
# File 'lib/digital_nomad_jobs/cli.rb', line 12

def welcome
  puts "================================================".blue 
  puts ")       Welcome to DIGITAL NOMAD JOBS!         (".blue  
  puts "================================================".blue
  puts "                 LET'S EXPLORE                  ".white.on_blue
end