Class: CommandLineInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/indeed_scraper/command_line_interface.rb

Constant Summary collapse

BASE_PATH =
"https://www.indeed.com"

Instance Method Summary collapse

Instance Method Details

#add_other_attributes_to_jobObject



103
104
105
106
107
108
# File 'lib/indeed_scraper/command_line_interface.rb', line 103

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

#clear_allObject



118
119
120
# File 'lib/indeed_scraper/command_line_interface.rb', line 118

def clear_all
  Job.all.clear
end

#display_jobObject



110
111
112
113
114
115
116
# File 'lib/indeed_scraper/command_line_interface.rb', line 110

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

#greetingObject



11
12
13
14
15
16
17
18
# File 'lib/indeed_scraper/command_line_interface.rb', line 11

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 "Hello, #{@user_name}!".green
  @user_name
end

#make_jobsObject



94
95
96
97
98
99
100
101
# File 'lib/indeed_scraper/command_line_interface.rb', line 94

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 4 attributes
end

#make_selectionObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/indeed_scraper/command_line_interface.rb', line 29

def make_selection
  puts "Select a number from the list above for more info or type 'back' to enter a new zipcode.".green
  user_input

#=> conditional statement depending on user's selection
  if @input.to_i.between?(1, 15)
      puts " "
      job = Job.all[@input.to_i-1]
      puts " "
      @url = BASE_PATH + job.job_url
      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
      menu_list
      @url
  elsif @input == "back"
    clear_all
    run_program
  else
    make_selection
  end
end


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/indeed_scraper/command_line_interface.rb', line 57

def menu_list
  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\n"

  user_input
  if @input.to_i == 1 #=> utilize #to_i to convert input to integer
    puts "To apply, right click on the link below then select 'Open URL'.\n\n".green
    puts @url
    menu_list
  elsif @input.to_i == 2
    display_job
  elsif @input.to_i == 3
    puts "See you later, #{@user_name}! Good luck on your job search!".green
  else
    menu_list
  end
end

#run_programObject



5
6
7
8
9
# File 'lib/indeed_scraper/command_line_interface.rb', line 5

def run_program 
    make_jobs
    add_other_attributes_to_job
    display_job
end

#user_inputObject



20
21
22
23
# File 'lib/indeed_scraper/command_line_interface.rb', line 20

def user_input
  input = gets.strip #remove white space
  @input = input
end

#verify_zipcodeObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/indeed_scraper/command_line_interface.rb', line 79

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
    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

#zipcodeObject



25
26
27
# File 'lib/indeed_scraper/command_line_interface.rb', line 25

def zipcode
  puts "Enter your 5 digit zipcode:".green
end