discourse/lib/trust_level.rb

44 lines
745 B
Ruby
Raw Normal View History

2013-02-06 03:16:51 +08:00
class TrustLevel
attr_reader :id, :name
class << self
def levels
{ new: 0,
basic: 1,
regular: 2,
experienced: 3,
advanced: 4,
moderator: 5 }
end
alias_method :Levels, :levels
def all
levels.map do |name_key, id|
TrustLevel.new(name_key, id)
end
end
def valid_level?(level)
levels.has_key?(level)
end
def compare(current_level, level)
(current_level || levels[:new]) >= levels[level]
end
2013-02-06 03:16:51 +08:00
def level_key(level)
levels.invert[level]
2013-02-06 03:16:51 +08:00
end
end
def initialize(name_key, id)
2013-02-26 00:42:20 +08:00
@name = I18n.t("trust_levels.#{name_key}.title")
2013-02-06 03:16:51 +08:00
@id = id
end
def serializable_hash
{ id: @id, name: @name }
2013-02-06 03:16:51 +08:00
end
end