Sha256: 48ed6dde5f9fb8b7507c8dd1fa6d993be133a22d79ea649526268fb4cc9d3c86

Contents?: true

Size: 636 Bytes

Versions: 2

Compression:

Stored size: 636 Bytes

Contents

class Category < ActiveRecord::Base
  validates_presence_of :name
  validates_uniqueness_of :name
  
  def validate
    unless %w(Income Expense).include?(self.kind)
      errors.add("kind", "#{self.kind.inspect} must be either of Income or Expense")
    end
  end

  # provides move_higher, move_lower, etc.
  # categories are indexed in those of the same kind
  acts_as_list :scope => 'kind == \'#{kind}\''

  def self.hashed
    {
      :income =>
      self.all(:conditions => {:kind => "Income"},  :order => "position"),
      :expense =>
      self.all(:conditions => {:kind => "Expense"}, :order => "position"),
    }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
moneyrail-0.1.4 app/models/category.rb
moneyrail-0.1.2 app/models/category.rb