Class: Controller
- Inherits:
-
Object
- Object
- Controller
- Defined in:
- lib/deedveloper/controller.rb
Instance Method Summary collapse
- #call ⇒ Object
- #display_detail ⇒ Object
- #get_detail(input) ⇒ Object
- #goodbye ⇒ Object
- #list_jobs ⇒ Object
- #search ⇒ Object
Instance Method Details
#call ⇒ Object
6 7 8 9 10 11 |
# File 'lib/deedveloper/controller.rb', line 6 def call #welcomes the user and initiates search puts "","░▒▓ Welcome to DEEDVELOPER, an Indeed.com search engine in Ruby! ▓▒░" puts "You need a job, son! Grab some coffee and let's get this bread...","" search end |
#display_detail ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/deedveloper/controller.rb', line 30 def display_detail #accepts user input, displays level two job information for selected job, and provides other options for user interaction: exit, list, and search input = nil while input != "exit" puts 'Enter the number of a job to see more info! Type "exit" to end search, "list" to see job listings again, or "search" to begin a new search.' input = gets.strip.downcase if input.to_i > Job.all.count puts "There aren't that many jobs!" elsif input.to_i >= 1 get_detail(input) elsif input == "list" list_jobs elsif input == "exit" goodbye elsif input == "search" puts "OK, let's search again!" # clears Job.all for repopulation by search method Job.all.clear search end end end |
#get_detail(input) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/deedveloper/controller.rb', line 53 def get_detail(input) #initiates further scraping and formats/displays additional job details for a user-selected job Scraper.scrape_detail(input) puts "","Job title: #{Job.all[input.to_i-1].title}", "Company: #{Job.all[input.to_i-1].company}", "Location: #{Job.all[input.to_i-1].location}", "Post date: #{Job.all[input.to_i-1].when_posted}", "Salary: #{Job.all[input.to_i-1].salary}", "Indeed posting: #{Job.all[input.to_i-1].job_url}","" end |
#goodbye ⇒ Object
64 65 66 67 |
# File 'lib/deedveloper/controller.rb', line 64 def goodbye puts "Enjoy your coffee! See you later." return exit end |
#list_jobs ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/deedveloper/controller.rb', line 21 def list_jobs #formats first level job information and displays it for the user puts "Check out these jobs:" Job.all.each.with_index(1) do |job, i| puts "#{i}. #{job.title} ◦ #{job.company}", "" end end |
#search ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/deedveloper/controller.rb', line 13 def search #calls first level scraper method, pulls the resulting data, and displays it for user interaction scraper = Scraper.new scraper.scrape_jobs list_jobs display_detail end |