Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created methods to parse through the CSV files and create objects #6

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

MDelarosa1993
Copy link
Owner

Created the initialize method and the helper method create_objects by passing through each CSV and putting them into an array with hashes in it. So ruby can work with the data much better. Also its converting each header to symbols. Created the Game and teams class so StatTracker knows where to go for the keys of each CSV file.

Comment on lines +17 to +36
def create_objects(path, statistics, tracker)
data = CSV.parse(File.read(path), headers: true, header_converters: :symbol)
data.map { |row| statistics.new(row, tracker) }
end

def highest_total_score
total_score.max
end

def lowest_total_score
total_score.min
end

def total_score
@games.map do |game|
home_goals = game.home_goals
away_goals = game.away_goals
home_goals + away_goals
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made great progress on this Melchor! I like the addition of a helper method here, it makes it look very clean.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I like this format and think the group should follow suit for the other methods as well. Once we have all of these methods written I think it might make sense to pull out the helper methods (like total_score) into a module file.

@@ -1,10 +1,39 @@
require 'csv'
Copy link
Collaborator

@TDManning TDManning Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: modify 'requires' as a spec_helper file

@reneemes reneemes merged commit 51ae06b into main Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants