2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-05 06:42:18 +08:00
|
|
|
class InvalidTrustLevel < StandardError; end
|
2014-11-17 22:02:10 +08:00
|
|
|
|
2013-03-01 20:07:44 +08:00
|
|
|
class TrustLevel
|
2014-11-17 22:02:10 +08:00
|
|
|
|
2013-02-28 21:08:56 +08:00
|
|
|
class << self
|
2014-09-05 06:42:18 +08:00
|
|
|
|
2014-11-17 22:02:10 +08:00
|
|
|
def [](level)
|
|
|
|
raise InvalidTrustLevel if !valid?(level)
|
2014-09-05 13:20:39 +08:00
|
|
|
level
|
2014-09-05 06:42:18 +08:00
|
|
|
end
|
|
|
|
|
2013-02-28 21:08:56 +08:00
|
|
|
def levels
|
2015-11-23 16:31:14 +08:00
|
|
|
@levels ||= Enum.new(:newuser, :basic, :member, :regular, :leader, start: 0)
|
2013-02-28 21:08:56 +08:00
|
|
|
end
|
|
|
|
|
2014-09-05 13:20:39 +08:00
|
|
|
def valid?(level)
|
2014-12-10 01:16:47 +08:00
|
|
|
valid_range === level
|
2014-09-05 13:20:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid_range
|
2014-11-17 22:02:10 +08:00
|
|
|
(0..4)
|
2013-02-28 21:08:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def compare(current_level, level)
|
2014-09-05 13:20:39 +08:00
|
|
|
(current_level || 0) >= level
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2014-11-17 22:02:10 +08:00
|
|
|
|
2021-06-02 04:11:48 +08:00
|
|
|
def name(level)
|
|
|
|
I18n.t("js.trust_levels.names.#{levels[level]}")
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2014-11-17 22:02:10 +08:00
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|