1
0
Fork 0
forked from OpenNeo/impress
impress/app/models/closet_visibility.rb

55 lines
920 B
Ruby
Raw Normal View History

2011-07-30 16:45:28 -07:00
module ClosetVisibility
class Level
attr_accessor :id, :name
def initialize(data)
data.each do |key, value|
send("#{key}=", value)
end
end
def description(subject=:items)
I18n.translate "closet_hangers.visibility.#{name}.description.#{subject}"
2011-07-30 16:45:28 -07:00
end
def human_name
I18n.translate "closet_hangers.visibility.#{name}.name"
end
def trading?
id >= LEVELS_BY_NAME[:trading].id
end
2011-07-30 16:45:28 -07:00
end
LEVELS = [
Level.new(
:id => 0,
:name => :private
2011-07-30 16:45:28 -07:00
),
Level.new(
:id => 1,
:name => :public
2011-07-30 16:45:28 -07:00
),
Level.new(
:id => 2,
: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