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
- #display_all_jobs ⇒ Object
- #exit_program ⇒ Object
- #greeting ⇒ Object
- #make_jobs ⇒ Object
- #make_selection(input = nil) ⇒ Object
- #menu_list(job_url = nil) ⇒ Object
- #run_program ⇒ Object
- #select_number ⇒ Object
- #user_input ⇒ Object
- #verify_zipcode ⇒ Object
- #zipcode ⇒ Object
Instance Method Details
#display_all_jobs ⇒ Object
103 104 105 106 107 108 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 103 def display_all_jobs Job.all.each.with_index(1) do |el, index| puts "#{index}" + ". " + "#{el.title}\n\n" end select_number end |
#exit_program ⇒ Object
110 111 112 113 114 115 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 110 def exit_program puts "See you later, #{@user_name}! Good luck on your job search!".green puts " /\\_/\\ ".magenta.blink puts " ( o.o ) ".magenta.blink puts " > ^ < \n\n".magenta.blink end |
#greeting ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 5 def greeting puts "Hello there! Welcome to Indeed Scraper Command Line Interface.".green puts "What is your name?".green @user_name = user_input.upcase if !@user_name.empty? puts " " puts "Hello, #{@user_name}!".green else greeting end @user_name end |
#make_jobs ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 38 def make_jobs zipcode 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 5 attributes end |
#make_selection(input = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 47 def make_selection(input = nil) if @input.to_i <= Job.all.size #&& @input.to_i != 0 #retrieve job object by index number @job = Job.all[(@input.to_i)-1] puts "TITLE: ".blue + "#{@job.title}\n" if !@job.title.empty? puts "COMPANY: ".blue + "#{@job.company}\n" if !@job.company.empty? puts "LOCATION: ".blue + "#{@job.location}\n" if !@job.location.empty? puts "SALARY: ".blue + "#{@job.salary}\n" if !@job.salary.empty? puts "DESCRIPTION: ".blue + "#{@job.description}\n" if !@job.description.empty? (@job.job_url) elsif @input.upcase == "EXIT" exit_program else select_number make_selection end end |
#menu_list(job_url = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 65 def (job_url = nil) puts " " puts "What do you want to do, #{@user_name}?".green puts "Select a number below:\n".green puts "1. Learn more" puts "2. Go back to list" puts "3. Enter new zipcode" puts "4. Exit\n\n" user_input if @input.to_i == 1 #=> utilize #to_i to convert input to integer system("open", "#{BASE_PATH + @job.job_url}") #=> automatically open job posting via terminal (job_url) elsif @input.to_i == 2 display_all_jobs make_selection(@input) elsif @input.to_i == 3 Job.clear_all run_program elsif @input.to_i == 4 exit_program else end end |
#run_program ⇒ Object
18 19 20 21 22 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 18 def run_program make_jobs display_all_jobs make_selection(@input) end |
#select_number ⇒ Object
33 34 35 36 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 33 def select_number puts "Enter a number from the list for more info or type 'exit' to exit program:".green user_input end |
#user_input ⇒ Object
28 29 30 31 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 28 def user_input input = gets.strip #remove white space @input = input end |
#verify_zipcode ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 92 def verify_zipcode if /^[0-9]{5}$/.match(@input) #=> check to see that zipcode has 5 digits puts "Great! Here's what we found for #{@input}.".green else puts "Hmm...that doesn't look right. Enter your 5 digit zipcode:".green user_input verify_zipcode end @input end |
#zipcode ⇒ Object
24 25 26 |
# File 'lib/indeed_scraper/command_line_interface.rb', line 24 def zipcode puts "Enter your 5 digit zipcode:".green end |