Skip to content

Instantly share code, notes, and snippets.

@sanakm
Created March 4, 2016 20:46
Show Gist options
  • Save sanakm/ce335de36359c8e526f5 to your computer and use it in GitHub Desktop.
Save sanakm/ce335de36359c8e526f5 to your computer and use it in GitHub Desktop.
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
},
]
def qualified_candidates(candidate_list)
candidate_list.select { |candidate| experienced?(candidate) }
end
def experienced?(candidate)
candidate[:years_of_experience] > 2
end
def find(id)
@candidates.each do |candidate|
return candidate if candidate[:id] == id
end
end
def qualified_candidates(candidate_list)
candidate_list.select do |candidate|
experienced?(candidate) &&
languages?(candidate) &&
date_applied?(candidate) &&
age?(candidate)
end
end
def experienced?(candidate)
candidate[:years_of_experience] > 2
end
def languages?(candidate)
candidate[:languages].include?('Python') || candidate[:languages].include?('Ruby')
end
def date_applied?(candidate)
candidate[:date_applied] > 15.days.ago.to_date
end
def age?(candidate)
candidate[:age] > 17
end
def ordered_by_qualifications(candidates)
candidates.sort_by {|c| [c[:years_of_experience], c[:github_points]]}.reverse
end
#p ordered_by_qualifications(@candidates)
def menu
tell = true
while (tell)
puts "Enter something"
entering = gets.chomp
case entering
when "id 5"
p find(5)
when "all"
puts @candidates
when "qualified"
p qualified_candidates(@candidates)
when "quit"
tell = false
end
end
end
p menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment