Skip to content

Instantly share code, notes, and snippets.

@pierrevalade
Created May 27, 2009 13:33
Show Gist options
  • Save pierrevalade/118643 to your computer and use it in GitHub Desktop.
Save pierrevalade/118643 to your computer and use it in GitHub Desktop.
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