-
-
Save libryder/5c5bf6460eb0887fea10 to your computer and use it in GitHub Desktop.
This file contains 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
class UserLevel | |
attr_reader :user | |
attr_accessor :level | |
LEVELS = { | |
1: 5, | |
2: 10, | |
3: 25, | |
4: 40 | |
} | |
def initialize(user) | |
@user = user | |
calculate_level | |
end | |
private | |
def calculate_level(user_points) | |
LEVELS.keys.each_pair do |numeric_level, points | | |
if user_points >= points | |
self.level = numeric_level | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment