2011-07-30 16:45:28 -07:00
|
|
|
module ClosetVisibility
|
|
|
|
class Level
|
|
|
|
attr_accessor :id, :name
|
|
|
|
attr_writer :description
|
|
|
|
|
|
|
|
def initialize(data)
|
|
|
|
data.each do |key, value|
|
|
|
|
send("#{key}=", value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-01 18:42:58 -08:00
|
|
|
def description(subject=:items)
|
|
|
|
I18n.translate "closet_hangers.visibility.#{name}.description.#{subject}"
|
2011-07-30 16:45:28 -07:00
|
|
|
end
|
2011-07-30 19:34:27 -07:00
|
|
|
|
|
|
|
def human_name
|
2013-01-01 18:42:58 -08:00
|
|
|
I18n.translate "closet_hangers.visibility.#{name}.name"
|
2011-07-30 19:34:27 -07:00
|
|
|
end
|
2013-12-27 11:49:46 -08:00
|
|
|
|
|
|
|
def trading?
|
|
|
|
id >= LEVELS_BY_NAME[:trading].id
|
|
|
|
end
|
2011-07-30 16:45:28 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
LEVELS = [
|
|
|
|
Level.new(
|
|
|
|
:id => 0,
|
2013-01-01 18:42:58 -08:00
|
|
|
:name => :private
|
2011-07-30 16:45:28 -07:00
|
|
|
),
|
|
|
|
Level.new(
|
|
|
|
:id => 1,
|
2013-01-01 18:42:58 -08:00
|
|
|
:name => :public
|
2011-07-30 16:45:28 -07:00
|
|
|
),
|
|
|
|
Level.new(
|
|
|
|
:id => 2,
|
2013-01-01 18:42:58 -08:00
|
|
|
:name => :trading
|
2011-07-30 16:45:28 -07:00
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
LEVELS_BY_NAME = {}.tap do |levels_by_name|
|
|
|
|
LEVELS.each do |level|
|
|
|
|
levels_by_name[level.id] = level
|
|
|
|
levels_by_name[level.name] = level
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.[](id)
|
|
|
|
LEVELS_BY_NAME[id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.levels
|
|
|
|
LEVELS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|