Beginner here. Have a custom class method that calculates the win probability of team_a and team_b if they were to play each other. In my view, I want to display those calculations. Trying to put this together with my limited understanding of how it works.
# team.rb
class Team
attr_reader :home_team_win_probability, :away_team_win_probability
def self.matchup(home_team, away_team)
home_team_win_probability = (home_team.rating - home_team.rating * away_team.rating) / (home_team.rating) + away_team.rating - 2 * home_team.rating * away_team.rating)
away_team_win_probability = 1 - home_team_win_probability
end
end
# teams_controller.rb
class TeamsController < ApplicationController
def matchups
@team_a = Team.find_by(rank: 2)
@team_b = Team.find_by(rank: 1)
@matchup = Team.matchup(@team_a, @team_b)
end
end
# matchups.html.erb
<h4>Matchup: <%= @team_a.name %> @ <%= @team_a.name %></h4>
# want to do something like this:
<h5>Home Team Win Probability: <%= @matchup.home_team_win_probability %> </h5>
<h5>Away Team Win Probability: <%= @matchup.away_team_win_probability %> </h5>
@matchup.home_team_win_probability yields error because @matchup just returns the last line (the away team probability in this case) @matchup.home_team_win_probability => undefined method home_team_win_probability for #<BigDecimal:0x007f860872b3f8
How do I call home_team_win_probability and away_team_win_probability as calculated in my custom class method? Thanks.