Files
nairobi/app/helpers/votes_helper.rb
Javi Martín 66759d2dc0 Apply StringConcatenation rule in some places
This rule was added in Rubocop 0.89.0. However, there are some false
positives when we don't use interpolation but simply concatenate in
order to avoid long lines. Even if there weren't false positives, there
are places where we concatenate to emphasize the point that we're adding
a certain character to a text.

We might reconsider this rule in the future, since we generally prefer
interpolation over concatenation.
2020-10-23 12:01:39 +02:00

31 lines
685 B
Ruby

module VotesHelper
def debate_percentage_of_likes(debate)
debate.likes.percent_of(debate.total_votes)
end
def votes_percentage(vote, debate)
return "0%" if debate.total_votes == 0
if vote == "likes"
"#{debate_percentage_of_likes(debate)}%"
elsif vote == "dislikes"
"#{100 - debate_percentage_of_likes(debate)}%"
end
end
def css_classes_for_vote(votes, votable)
case votes[votable.id]
when true
{ in_favor: "voted", against: "no-voted" }
when false
{ in_favor: "no-voted", against: "voted" }
else
{ in_favor: "", against: "" }
end
end
def voted_for?(votes, votable)
votes[votable.id]
end
end