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