class CommandLineInterface

Constants

BASE_PATH

Public Instance Methods

display_all_jobs() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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?
    menu_list(@job.job_url)
  elsif @input.upcase == "EXIT"
    exit_program
  else
    select_number
    make_selection
  end
end
menu_list(job_url = nil) click to toggle source
run_program() click to toggle source
# File lib/indeed_scraper/command_line_interface.rb, line 18
def run_program 
  make_jobs
  display_all_jobs
  make_selection(@input)
end
select_number() click to toggle source
# 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() click to toggle source
# File lib/indeed_scraper/command_line_interface.rb, line 28
def user_input
  input = gets.strip #remove white space
  @input = input
end
verify_zipcode() click to toggle source
# 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() click to toggle source
# File lib/indeed_scraper/command_line_interface.rb, line 24
def zipcode
  puts "Enter your 5 digit zipcode:".green
end