Class: WeWorkRemotely::Controller
- Inherits:
-
Object
- Object
- WeWorkRemotely::Controller
- Defined in:
- lib/weworkremotely/controller.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #list_all ⇒ Object
- #list_by_category(category) ⇒ Object
- #show_job(id) ⇒ Object
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
3 4 5 6 |
# File 'lib/weworkremotely/controller.rb', line 3 def initialize scraper = WeWorkRemotely::Scraper.new scraper.scrape end |
Instance Method Details
#call ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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/weworkremotely/controller.rb', line 8 def call input = "" while input != "exit" puts "Please make your selection." puts "List: " puts " (a)ll" puts " (p)rogramming" puts " (d)esign" puts " de(v)ops/sysadmin" puts " (m)arketing" puts " (c)opywriting" puts " customer (s)upport" puts " (b)usiness/exec & management" puts " all (o)ther jobs" puts "You can also look by job (n)umber." puts "To exit, type 'exit'." input = gets.strip case input when "a" list_all when "p" list_by_category("programming") when "d" list_by_category("design") when "v" list_by_category("devops") when "m" list_by_category("marketing") when "c" list_by_category("copywriting") when "s" list_by_category("customer support") when "o" list_by_category("other") when "b" list_by_category("business") when "n" puts "Which job number would you like to see?" number = gets.strip show_job(number) end end end |
#list_all ⇒ Object
52 53 54 55 56 |
# File 'lib/weworkremotely/controller.rb', line 52 def list_all WeWorkRemotely::Job.all.each do |j| puts "#{j.id}. #{j.name} for #{j.company.name}" end end |
#list_by_category(category) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/weworkremotely/controller.rb', line 82 def list_by_category(category) puts "" c = WeWorkRemotely::Category.find_by_name(category) puts "There are <#{c.jobs.length}> #{category} jobs!" c.jobs.each do |job| puts "#{job.id}. #{job.name} for #{job.company.name}" end puts "" end |
#show_job(id) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/weworkremotely/controller.rb', line 58 def show_job(id) if j = WeWorkRemotely::Job.find_by_id(id) puts "===== Job Details =====" puts "" puts "Job ID: #{j.id}" puts "Title: #{j.name}" puts "Company: #{j.company.name}" puts "Category: #{j.category.name.capitalize}" puts "Posted: #{j.published_date}" puts "Job URL: #{j.url}" puts "Job Description:" puts "#{j.description.squeeze("\n")}" puts "" puts "=======================" puts "" else puts "======== ERROR ========" puts "" puts "Could not find a job with that ID." puts "" puts "=======================" end end |