Last active
December 29, 2015 14:48
-
-
Save jmoon90/7686064 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative "test_reader" | |
| require_relative "test_scores.rb" | |
| read_class= TestReader.new | |
| read_class.parse_data | |
| read_class.student_grade | |
| read_class.test_score | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'csv' | |
| class TestReader | |
| attr_reader :parse_data | |
| def initialize | |
| @student_grades = [] | |
| @student = {} | |
| end | |
| def parse_data | |
| CSV.foreach("test_scores.csv", :headers => true) do |row| | |
| @student_grades << row | |
| end | |
| end | |
| def student_grade | |
| @student_grades.each do |student| | |
| @student[student["Name"]] = student["Grade"].to_i | |
| end | |
| end | |
| def test_score | |
| TestScores.new(@student).student_bracket | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Name | Grade | |
|---|---|---|
| John Smith | 75 | |
| Sally Field | 85 | |
| Jane Doe | 93 | |
| Gus Grumpy | 98 | |
| Mark Marcus | 68 | |
| Vic Victor | 83 | |
| Frank Furter | 89 | |
| John Bello | 78 | |
| Liz Branch | 99 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pry' | |
| class TestScores | |
| def initialize(student) | |
| @student = student | |
| @bracket = [] | |
| @high_grade = [] | |
| @medium_grade = [] | |
| @below_avg = [] | |
| @low_grade = [] | |
| end | |
| def student_bracket | |
| @student.each do |grade| | |
| bracket(grade) | |
| end | |
| bracket_message | |
| end | |
| def bracket(grade) | |
| if grade[1] >= 90 | |
| @high_grade << grade | |
| elsif grade[1] >= 80 && grade[1] < 90 | |
| @medium_grade << grade | |
| elsif grade[1] >= 70 && grade[1] < 80 | |
| @below_avg << grade | |
| else | |
| @low_grade << grade | |
| end | |
| end | |
| def bracket_message | |
| puts "=== >= 90 ===" | |
| @high_grade.each do |student_grade| | |
| puts student_grade[0] | |
| end | |
| puts "=== >= 80 ===" | |
| @medium_grade.each do |student_grade| | |
| puts student_grade[0] | |
| end | |
| puts "=== >= 70 ===" | |
| @below_avg.each do |student_grade| | |
| puts student_grade[0] | |
| end | |
| puts "=== < 70 ===" | |
| @low_grade.each do |student_grade| | |
| puts student_grade[0] | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment