Created
May 27, 2009 13:33
-
-
Save pierrevalade/118643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Category | |
# name is book, movie | |
attr_accessor :name, :path | |
def initialize(n, path) | |
self.name = n.to_s # movie, book | |
self.path = path | |
end | |
# Movies, Livres, Places | |
# translated | |
def to_s | |
I18n.t("categories.#{plural}") | |
end | |
# movies, books | |
def plural | |
name.pluralize | |
end | |
# movies | |
def to_query | |
name | |
end | |
def self.all | |
categories = [] | |
order = [:movie, :book, :place, :event, :video, :link] | |
order.each { |category| categories << get(category) } | |
categories | |
end | |
def self.get(category) | |
# category = category.to_s.downcase | |
hash[category] | |
end | |
# TODO: add this to an .yml | |
def self.hash | |
@hash ||= {:movie => Category.new(:movie, '/movies'), :book => Category.new(:book, '/books'), :place => Category.new(:place, '/places'), :event => Category.new(:event, '/events'), :video => Category.new(:video, '/videos'), :link => Category.new(:link, '/links')} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment