Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. # In this file we define the methods to help filter out candidates
  2. # This way, we keep these methods separated from other potential parts of the program
  3.  
  4. filter.rb
  5.  
  6. def find(id)
  7. #if the id is equal to the passed parameter, return candidate with that id
  8. @candidates.each do |candidate|
  9. if candidate[:id] == id
  10. return candidate
  11. end
  12. end
  13. return "no match!"
  14. end
  15.  
  16. def experienced?(candidate)
  17. if candidate[:years_of_experience] <= 2
  18. return false
  19. else
  20. return true
  21. end
  22. end
  23.  
  24. def candidates_experienced(array)
  25. array.select { |candidate| candidate[:years_of_experience] >= 2 }
  26. end
  27.  
  28. def github_points(array)
  29. array.select { |candidate| candidate[:github_points] >= 100 }
  30. end
  31.  
  32. def languages(array) #iterate over @candidates, for each candidate, access languages,
  33. #iterate over each language array and if array contains string "Ruby" or "Python", return true
  34. array.select { |candidate| candidate[:languages].include?("Ruby" || "Python")}
  35. end
  36.  
  37. def find_age(array) #iterate through @candidates, for each candidate, iterate through key
  38. #and value, if the key is age and the value of age is greater or equal to 18, return whole candidate
  39. array.select { |candidate| candidate [:age] >= 18 }
  40. end
  41.  
  42. def applied(array) #
  43. array.select { |candidate| candidate [:date_applied] >= 15.days.ago.to_date }
  44. end
  45.  
  46. def qualified_candidates(array)
  47. github_points(candidates_experienced(languages(find_age(applied(array)))))
  48. end
  49.  
  50. def ordered_by_qualifications(array)
  51. array.sort { |candidate1, candidate2|
  52. if candidate1 [:years_of_experience] == candidate2 [:years_of_experience]
  53. candidate1 [:github_points] <=> candidate2 [:github_points]
  54. else
  55. candidate1 [:years_of_experience] <=> candidate2[:years_of_experience]
  56. end
  57. }.reverse
  58. end
  59.  
  60.  
  61. main.rb
  62.  
  63. # This is the main entrypoint into the program
  64. # It requires the other files/gems that it needs
  65.  
  66. require 'pry'
  67. require './candidates'
  68. require './filters'
  69.  
  70. def display_commands
  71. puts "\n" +
  72. "Please choose one of the following:\n" +
  73. "\n"
  74. "find_1\n" +
  75. "all\n" +
  76. "qualified\n" +
  77. "quit\n" +
  78. "\n"
  79. end
  80.  
  81. def find_1
  82. end
  83.  
  84. ## Your test code can go here
  85. #binding.pry
  86.  
  87. # puts experienced?(@candidates[2])
  88. # puts candidates_experienced(@candidates)
  89. # puts find(3)
  90. # puts github_points(@candidates)
  91. # puts language(@candidates)
  92. # puts find_age(@candidates)
  93. # puts applied(@candidates)
  94. # puts qualified_candidates(@candidates)
  95. # puts ordered_by_qualifications(@candidates)
  96. puts display_commands
  97.  
  98. candidates.rb
  99.  
  100. require 'active_support/all'
  101.  
  102. @candidates = [
  103. {
  104. id: 5,
  105. years_of_experience: 4,
  106. github_points: 293,
  107. languages: ['C', 'Ruby', 'Python', 'Clojure'],
  108. date_applied: 5.days.ago.to_date,
  109. age: 26
  110. },
  111. {
  112. id: 7,
  113. years_of_experience: 1,
  114. github_points: 145,
  115. languages: ['JavaScript', 'Ruby', 'Go', 'Erlang'],
  116. date_applied: 15.days.ago.to_date,
  117. age: 19
  118. },
  119. {
  120. id: 9,
  121. years_of_experience: 6,
  122. github_points: 435,
  123. languages: ['JavaScript', 'SQL', 'C#'],
  124. date_applied: 1.day.ago.to_date,
  125. age: 32
  126. },
  127. {
  128. id: 10,
  129. years_of_experience: 3,
  130. github_points: 232,
  131. languages: ['Java', 'Ruby', 'JavaScript'],
  132. date_applied: 12.days.ago.to_date,
  133. age: 31
  134. },
  135. {
  136. id: 11,
  137. years_of_experience: 12,
  138. github_points: 32,
  139. languages: ['VB', 'Cobol', 'Fortran'],
  140. date_applied: 2.days.ago.to_date,
  141. age: 42
  142. },
  143. {
  144. id: 13,
  145. years_of_experience: 2,
  146. github_points: 328,
  147. languages: ['Python', 'Ruby', 'JavaScript'],
  148. date_applied: 4.days.ago.to_date,
  149. age: 25
  150. },
  151. {
  152. id: 15,
  153. years_of_experience: 1,
  154. github_points: 400,
  155. languages: ['JavaScript', 'Ruby'],
  156. date_applied: 3.days.ago.to_date,
  157. age: 16
  158. },
  159. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement