Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ToeKneeLeg
Created August 28, 2015 02:16
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 ToeKneeLeg/ea91f0d0977d39530715 to your computer and use it in GitHub Desktop.
Save ToeKneeLeg/ea91f0d0977d39530715 to your computer and use it in GitHub Desktop.
Candidates
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
#takes in an id and returns the candidate with that id
def find(id)
outcome = "No such ID"
@candidates.each do |i|
if i[:id] == id
outcome = i
end
end
pp outcome
end
#returns true if candidate has 2 or more years of experience
def experienced?(candidate)
if candidate[:years_of_experience] >= 2
return true
else
return false
end
end
#returns true if candidate has 100 and more git point
def got_git?(candidate)
if candidate[:github_points] >= 100
return true
else
return false
end
end
#returns true if candidate is older than 17
def old_enough?(candidate)
if candidate[:age] > 17
return true
else
return false
end
end
#returns true if applied date is within the last 15 days
def applied?(candidate)
if Date.today - candidate[:date_applied] <= 15
return true
else
return false
end
end
#returns true if candidate knows either ruby or python
def got_ruby?(candidate)
if candidate[:languages].include?("Ruby") || candidate[:languages].include?("Ruby")
return true
else
return false
end
end
#filters candidate with requirement
def qualified_candidates(candidates)
passed = []
candidates.each do |current_candidate|
if experienced?(current_candidate) && got_git?(current_candidate)
if got_ruby?(current_candidate) && old_enough?(current_candidate)
if applied?(current_candidate)
passed << current_candidate
end
end
end
end
pp passed
end
#returns candidates ordered by experience then by github point
def ordered_by_qualifications(candidates)
new_list = candidates.sort do |a, b|
if a[:years_of_experience] != b[:years_of_experience]
a[:years_of_experience]<=>b[:years_of_experience]
else
a[:github_points]<=>b[:github_points]
end
end
pp new_list.reverse
end
#REPL-based Menu
def repl
keep_looping = true
user_input = nil
while keep_looping do
puts "Menu options: find, all, qualified, quit"
user_input = gets.chomp
if user_input == "find"
puts "Input an ID number you're looking for"
find_var = gets.chomp.to_i
find(find_var)
end
if user_input == "all"
@candidates.each do |i|
puts i
end
end
if user_input == "qualified"
qualified_candidates(@candidates)
end
if user_input == "quit"
keep_looping = false
end
end
end
# This is the main entrypoint into the program
# It requires the other files/gems that it needs
require 'pry'
require './candidates'
require './filters'
repl
## Youtest code can go he
# qualified_candidates(@candidates)
binding.pry
# pp qualified_candidates()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment