-
-
Save clark-teeple/2c1a7a535544a2d5e604 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}, | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 find(id) | |
counter = 0 | |
@candidates.each do |candidate| | |
if candidate[:id] == id | |
counter += 1 | |
return candidate | |
end | |
end | |
if couter == 0 | |
return nil | |
end | |
end | |
def experienced?(candidate) | |
if candidate[:years_of_experience] >= 2 | |
return true | |
else | |
return false | |
end | |
end | |
def check_qualifications(candidate) | |
var1 = experienced?(candidate) | |
var2 = candidate[:github_points] >= 100 | |
var3 = candidate[:languages].include?("Ruby" || "Python") | |
var4 = candidate[:date_applied] >= 15 | |
var5 = candidate[:age] > 17 | |
if var1 == true && var2 == true && var3 ==true && var4 == true && var5 == true | |
return true | |
else | |
return false | |
end | |
end | |
def qualified_candidates() | |
qualified = [] | |
@candidates.each do |candidate| | |
if check_qualifications(candidate) | |
qualified << candidate | |
end | |
end | |
return sort_by_qualifications(qualified) | |
end | |
def sort_by_qualifications(candidates) | |
git_sort = candidates.sort_by! do |candidate| | |
candidate[:github_points] | |
end | |
first_sort = git_sort.sort_by! do |candidate| | |
candidate[:years_of_experience] | |
end | |
return first_sort.reverse | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
command = nil | |
while command != "QUIT" | |
puts "MENU: BY ID, ALL, QUALIFIED, QUIT" | |
puts "> " | |
command = gets.chomp | |
if command == "BY ID" | |
puts "ENTER ID #" | |
puts "> " | |
id = gets.chomp | |
to_put = @candidates.detect {|candidate| candidate[:id] == id.to_i} | |
pp to_put | |
elsif command == "QUALIFIED" | |
pp qualified_candidates | |
elsif command == "QUIT" | |
puts "" | |
else | |
puts "INVALID ENTRY" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment