Skip to content

Instantly share code, notes, and snippets.

@jilucev
Created March 7, 2014 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jilucev/9404782 to your computer and use it in GitHub Desktop.
Save jilucev/9404782 to your computer and use it in GitHub Desktop.
# In this file we define the methods to help filter out candidates
# This way, we keep these methods separated from other potential parts of the program
def experienced?(candidate)
amount_of_experience = candidate[:years_of_experience]
if amount_of_experience > 2
return true
else
return false
end
end
def find(candidates, id_num)
candidates.each do |candidate|
if candidate[:id] == id_num
puts candidate
end
end
end
def qualified_candidates(candidates)
candidates.select do |candidate|
experienced?(candidate) &&
candidate[:github_points] > 100 &&
candidate[:languages].include?('Ruby') || candidate[:languages].include?('Python') &&
candidate[:date_applied] < 15 &&
candidate[:age] >= 18
end
end
def ordered_by_qualifications(candidates)
candidates.sort do |a, b|
if a[:years_of_experience] > b[:years_of_experience]
-1
elsif a[:years_of_experience] < b[:years_of_experience]
1
elsif a[:years_of_experience] == b[:years_of_experience]
if a[:github_points] > b[:github_points]
-1
elsif a[:github_points] < b[:github_points]
1
else
0
end
else
0
end
end
end
def ask
puts "Welcome to hiring helper! Type 'find' to find candidates, 'all' to see a listing of all candidates, 'qualified' to see a listing of candidates that meet your criteria, and 'quit' to get the hell out of here and drink beer."
while true
print ">"
reply = gets.chomp.downcase
if reply == 'find'
puts "#{find(@candidates,1)}"
end
if reply == "all"
pp @candidates
end
if reply == "qualified"
puts "#{qualified_candidates(@candidates)}"
end
if reply == 'quit'
break
end
end
end
ask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment