Codeclimate says it has a lot of duplication.
def award_points_to_user_if_activity_completed(user_activity)
if user_activity.completed?
if user_activity.total_steps_covered >= user_activity.challenge.number_of_steps && user_activity.total_steps_covered < (user_activity.challenge.number_of_steps + 100000) && user_activity.level == "Basic"
points = user_activity.total_steps_covered
current_user.award_points(points)
return "Congrats for finishing the challenge. You just got #{points} points. Now pick another challenge."
end
if user_activity.total_steps_covered >= (user_activity.challenge.number_of_steps + 100000) && user_activity.level == "Basic"
points = user_activity.total_steps_covered
current_user.award_points(points)
return "Congrats. You not only finished the basic challenge but also overcame the advanced challenge. Make sure you choose a better challenge to earn more points."
end
if user_activity.total_steps_covered >= user_activity.challenge.number_of_steps && user_activity.level == "Advanced"
points = 2*(user_activity.total_steps_covered - (user_activity.challenge.number_of_steps - 100000)) + user_activity.challenge.number_of_steps - 100000
current_user.award_points(points)
return "Congrats for finishing the challenge. You just got #{points} points. Now pick another challenge."
end
if user_activity.total_steps_covered < (user_activity.challenge.number_of_steps - 100000) && user_activity.level == "Advanced"
points = user_activity.total_steps_covered
current_user.award_points(points)
return "Oops. You missed your basic target. I think you should go for a lower target to get points and badges. It is ok. People often get stuck based on their lifestyls. That is why we are here. "
end
if user_activity.total_steps_covered < user_activity.challenge.number_of_steps && user_activity.level == "Basic"
points = user_activity.total_steps_covered
current_user.award_points(points)
return "Oops you missed the target. Based on your lifestyle you can choose one that suits you better."
end
if user_activity.total_steps_covered >= (user_activity.challenge.number_of_steps - 100000) && user_activity.total_steps_covered < user_activity.challenge.number_of_steps && user_activity.level == "Advanced"
points = user_activity.total_steps_covered
current_user.award_points(points)
return "Congrats. You finished the basic challenge but not the advanced challenge. It is ok. But this time we want to make sure you go for the advanced challenge first."
end
end
end