Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
- filter.rb
- def find(id)
- #if the id is equal to the passed parameter, return candidate with that id
- @candidates.each do |candidate|
- if candidate[:id] == id
- return candidate
- end
- end
- return "no match!"
- end
- def experienced?(candidate)
- if candidate[:years_of_experience] <= 2
- return false
- else
- return true
- end
- end
- def candidates_experienced(array)
- array.select { |candidate| candidate[:years_of_experience] >= 2 }
- end
- def github_points(array)
- array.select { |candidate| candidate[:github_points] >= 100 }
- end
- def languages(array) #iterate over @candidates, for each candidate, access languages,
- #iterate over each language array and if array contains string "Ruby" or "Python", return true
- array.select { |candidate| candidate[:languages].include?("Ruby" || "Python")}
- end
- def find_age(array) #iterate through @candidates, for each candidate, iterate through key
- #and value, if the key is age and the value of age is greater or equal to 18, return whole candidate
- array.select { |candidate| candidate [:age] >= 18 }
- end
- def applied(array) #
- array.select { |candidate| candidate [:date_applied] >= 15.days.ago.to_date }
- end
- def qualified_candidates(array)
- github_points(candidates_experienced(languages(find_age(applied(array)))))
- end
- def ordered_by_qualifications(array)
- array.sort { |candidate1, candidate2|
- if candidate1 [:years_of_experience] == candidate2 [:years_of_experience]
- candidate1 [:github_points] <=> candidate2 [:github_points]
- else
- candidate1 [:years_of_experience] <=> candidate2[:years_of_experience]
- end
- }.reverse
- end
- main.rb
- # This is the main entrypoint into the program
- # It requires the other files/gems that it needs
- require 'pry'
- require './candidates'
- require './filters'
- def display_commands
- puts "\n" +
- "Please choose one of the following:\n" +
- "\n"
- "find_1\n" +
- "all\n" +
- "qualified\n" +
- "quit\n" +
- "\n"
- end
- def find_1
- end
- ## Your test code can go here
- #binding.pry
- # puts experienced?(@candidates[2])
- # puts candidates_experienced(@candidates)
- # puts find(3)
- # puts github_points(@candidates)
- # puts language(@candidates)
- # puts find_age(@candidates)
- # puts applied(@candidates)
- # puts qualified_candidates(@candidates)
- # puts ordered_by_qualifications(@candidates)
- puts display_commands
- candidates.rb
- 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
- },
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement