Skip to content

Instantly share code, notes, and snippets.

@laurenachoo
Last active August 29, 2015 14:20
Show Gist options
  • Save laurenachoo/2583dfbb5d0356b4aad9 to your computer and use it in GitHub Desktop.
Save laurenachoo/2583dfbb5d0356b4aad9 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
},
]
def experienced?(candidate)
if candidate[:years_of_experience] >= 2
true
else
false
end
end
def find(id)
@candidates.each do |candidate|
if candidate[:id] == id
return candidate
end
end
end
def qualified_candidates(candidates)
selected_candidates = []
candidates.each do |candidate|
if dev_experience(candidate)
selected_candidates << candidate
end
end
puts selected_candidates
end
def dev_experience(candidate)
candidate[:years_of_experience] >= 2 &&
candidate[:github_points] >= 100 &&
candidate[:languages].include?("Ruby") || candidate[:languages].include?("Python") &&
candidate[:date_applied] >= 15.days.ago.to_date &&
candidate[:age] >= 18
end
def ordered_by_qualifications
puts @candidates.sort_by { |ppl| [ppl[:years_of_experience], ppl[:github_points]] }.reverse
end
#require 'pry'
require './candidates'
require './filters'
#binding.pry
find(1)
puts experienced?(@candidates[0])
loop do
puts "Enter command"
input = gets.chomp.downcase
case input
when "find"
puts "Enter ID: "
puts find(gets.chomp.to_i)
when "all"
pp @candidates
when "qualified"
puts ordered_by_qualifications
when "quit"
break
else
puts "Please enter it one more time"
end
end
@monicao
Copy link

monicao commented May 4, 2015

https://gist.github.com/laurenachoo/2583dfbb5d0356b4aad9#file-filters-rb-L10

Take a look at the detect method for Ruby Enumerables. (Google: ruby enumerable select)

https://gist.github.com/laurenachoo/2583dfbb5d0356b4aad9#file-filters-rb-L20

Rename dev_experience to include ? and a verb.

https://gist.github.com/laurenachoo/2583dfbb5d0356b4aad9#file-filters-rb-L19

Refactor using select.

https://gist.github.com/laurenachoo/2583dfbb5d0356b4aad9#file-filters-rb-L36

Replace puts with return and let main.rb handle displaying data to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment