Class: CommandLineInterface
- Inherits:
-
Object
- Object
- CommandLineInterface
- Defined in:
- lib/indeed_scraper/command_line_interface.rb
Constant Summary collapse
- BASE_PATH =
"https://www.indeed.com"
Instance Method Summary collapse
- #add_other_attributes_to_job ⇒ Object
- #display_job ⇒ Object
- #greeting ⇒ Object
- #make_jobs ⇒ Object
- #make_selection ⇒ Object
- #menu_list ⇒ Object
- #run_program ⇒ Object
-
#user_input ⇒ Object
User’s input.
- #verify_zipcode ⇒ Object
Instance Method Details
#add_other_attributes_to_job ⇒ Object
101 102 103 104 105 106 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 101 def add_other_attributes_to_job Job.all.each do |job| other_details = Scraper.scrape_job_post(BASE_PATH + job.job_url) job.add_job_attributes(other_details) end end |
#display_job ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 108 def display_job Job.all.each.with_index(1) do |el, index| #if index <= 4 #=> displays first 5 jobs in @@all array puts "#{index}" + ". " + "#{el.title}\n\n" end make_selection end |
#greeting ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 12 def greeting puts "Hello there! Welcome to Indeed Scraper Command Line Interface.".green puts "What is your name?".green @user_name = user_input puts " " puts "Aloha, #{@input}!".green puts "Enter your 5 digit zipcode:".green end |
#make_jobs ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 93 def make_jobs user_input puts " " verify_zipcode jobs_array = Scraper.scrape_index_page(@input) Job.create_from_collection(jobs_array) # creates an array of job objects with 4 attributes end |
#make_selection ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 27 def make_selection puts " " puts "Select a number from the list above for more info.".green puts "Enter a number:".green user_input if @input.to_i.between?(1, 15) puts " " job = Job.all[@input.to_i-1] puts " " puts "TITLE: ".blue + "#{job.title}\n" if !job.title.empty? puts "COMPANY: ".blue + "#{job.company}\n" if !job.company.empty? puts "HOURS/SALARY: ".blue + "#{job.type}\n" if !job.type.empty? puts "LOCATION: ".blue + "#{job.location}\n\n" if !job.location.empty? if !job.description.empty? puts "DESCRIPTION: \n".blue puts "#{job.description}\n" end else make_selection end end |
#menu_list ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 52 def puts " " puts "What do you want to do, #{@user_name}?".green puts "Enter a number:\n".green puts "1. Apply" puts "2. Go back" puts "3. Exit\n" user_input # binding.pry if @input.to_i == 1 job = Job.all[@input.to_i-1] puts "To apply, right click on the link below then select 'Open URL'.".green puts " " puts BASE_PATH + job.job_url elsif @input.to_i == 2 display_job elsif @input.to_i == 3 puts " " puts "See you later, #{@user_name}! Good luck on your job search!".green else end end |
#run_program ⇒ Object
5 6 7 8 9 10 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 5 def run_program greeting make_jobs add_other_attributes_to_job display_job end |
#user_input ⇒ Object
User’s input
22 23 24 25 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 22 def user_input input = gets.strip #remove white space @input = input end |
#verify_zipcode ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 78 def verify_zipcode if /^[0-9]{5}$/.match(@input) puts "Great! We found some cool jobs for #{@input}.".green puts "Loading may take a few moments, so in the meantime, please enjoy this cute cat: \n\n\n".green puts " /\\_/\\ ".magenta.blink puts " ( o.o ) ".magenta.blink puts " > ^ < \n\n\n\n".magenta.blink else puts "Hmm...that doesn't look right. Enter your 5 digit zipcode:".green user_input verify_zipcode end @input end |