app/models/spud_calendar.rb in tb_events-1.1.2 vs app/models/spud_calendar.rb in tb_events-1.2.0.beta1

- old
+ new

@@ -1,12 +1,28 @@ class SpudCalendar < ActiveRecord::Base has_many :spud_calendar_events, :dependent => :destroy - validates_presence_of :title, :color + validates_presence_of :title validates :identifier, :presence => true, :uniqueness => true before_validation :set_identifier - scope :with_identifier, ->(identifier){ where(:identifier => identifier).first } + def self.with_identifier(identifier) + where(:identifier => identifier).first + end + + def color + modulo = (self.id-1) % COLORS.length + return COLORS[modulo] + end + + COLORS = [ + '4D854B', + 'f89406', + 'b94a48', + '3a87ad', + '999999', + '333333' + ] private def set_identifier if identifier.nil? && title.present?