Project

General

Profile

Download (582 Bytes) Statistics
| Branch: | Tag: | Revision:
class UserFact < ActiveRecord::Base
belongs_to :user
belongs_to :fact_name

validates :andor, :inclusion => {:in => %w{and or}}
validates :operator, :inclusion => {:in => %w{= != > >= < <= }}
validates :fact_name, :criteria, :user, :presence => true
before_validation :set_defaults

def to_s
n = user.try(:name) || _("Unknown user")
fn = fact_name.try(:name) || _("Unknown fact")
"#{n}:#{fn}:#{criteria.empty? ? "Empty" : criteria}:#{operator}:#{andor}"
end

private
def set_defaults
self.operator ||= "="
self.andor ||= "or"
end

end
(47-47/51)