Skip to content

Instantly share code, notes, and snippets.

@charmainetham
Created April 29, 2016 18:48
Show Gist options
  • Save charmainetham/fe9e70855676112e11597f058cbf86d6 to your computer and use it in GitHub Desktop.
Save charmainetham/fe9e70855676112e11597f058cbf86d6 to your computer and use it in GitHub Desktop.
Candidates assignment
require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
},
{
id: 7,
years_of_experience: 1,
github_points: 145,
languages: ['JavaScript', 'Ruby', 'Go', 'Erlang'],
date_applied: 15.days.ago.to_date,
age: 19
},
{
id: 9,
years_of_experience: 6,
github_points: 435,
languages: ['JavaScript', 'SQL', 'C#'],
date_applied: 1.day.ago.to_date,
age: 32
},
{
id: 10,
years_of_experience: 3,
github_points: 232,
languages: ['Java', 'Ruby', 'JavaScript'],
date_applied: 12.days.ago.to_date,
age: 31
},
{
id: 11,
years_of_experience: 12,
github_points: 32,
languages: ['VB', 'Cobol', 'Fortran'],
date_applied: 2.days.ago.to_date,
age: 42
},
{
id: 13,
years_of_experience: 2,
github_points: 328,
languages: ['Python', 'Ruby', 'JavaScript'],
date_applied: 4.days.ago.to_date,
age: 25
},
{
id: 15,
years_of_experience: 1,
github_points: 400,
languages: ['JavaScript', 'Ruby'],
date_applied: 3.days.ago.to_date,
age: 16
},
]
# 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
#evaluating if the candidate has more than 2 years of experience
def experienced?(candidate)
candidate[:years_of_experience] >= 2
end
#outputing candidate for specific id numbers
def find(id)
@candidates.each do |cand|
if cand[:id] == id
return cand
end
end
return nil
end
#are they Git savy?
def git?(candidate)
candidate[:github_points] >=100
end
# is the candidate proficient in ruby and java?
def ruby_andjava?(candidate)
candidate[:languages].include?("Ruby" || "Python")
end
#finding out if the candidate applied within 15 days
def less15?(candidate)
candidate[:date_applied] >= 15.days.ago.to_date
end
#is my candidate an adult/
def adult?(candidate)
candidate[:age] > 17
end
#Which candidates are qualified
def qualified_candidates(candidates)
@candidates.select do |candidate|
experienced?(candidate)&&git?(candidate)\
&&ruby_andjava?(candidate)&&less15?(candidate)\
&&adult?(candidate)
end
end
#SORTING by years of experience and github points
def ordered_by_qualifications(candidates)
candidates.sort_by{ |x| [x[:years_of_experience], x[:github_points]]}.reverse
end
# This is the main entrypoint into the program
# It requires the other files/gems that it needs
#require 'pry'
require './candidates'
require './filters'
## Your test code can go here
#binding.pry
#puts experienced?(@candidates[1])
#puts find(5)
#puts qualified_candidates(@candidates)
#puts ordered_by_qualifications(@candidates)
loop do
puts "What command would you like to use? find/ all/ qualified/ quit"
first_input = gets.chomp.downcase
if first_input == "quit"
break
end
if first_input == "find"
puts "which id would you like to look up?"
get_id = gets.chomp.to_i
if find(get_id) != nil
puts "Candidate: #{find(get_id)}"
else
puts "invalid id"
end
end
if first_input == "all"
puts "List of candidates : #{@candidates}"
end
if first_input == "qualified"
puts "List of qualified candidates: #{qualified_candidates(@candidates)}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment