Sha256: 79d937a9b96e72415dce6be7f8696bc0106aad7d59c8e0d9329cfd8a12cb981a
Contents?: true
Size: 967 Bytes
Versions: 3
Compression:
Stored size: 967 Bytes
Contents
class Activity < ActiveRecord::Base # Associations belongs_to :project belongs_to :person validates :project, :presence => true, :allow_blank => false validates :person, :presence => true, :allow_blank => false # Scopes scope :by_date, lambda {|value| where(:date => value)} # Duration validates :duration, :presence => true, :format => {:with => /[0-9]{1,2}([:.][0-9]{1,2})/} validates_date :date, :allow_nil => false, :allow_blank => false def duration=(value) if value.match(/:/) hours, minutes = value.split(':') write_attribute(:duration, hours.to_i + BigDecimal.new(minutes) / 60) else write_attribute(:duration, value) end end def to_s "%s: %0.2fh" % [project.name, duration] end # Work day belongs_to :work_day, :autosave => true after_save :update_work_day after_destroy :update_work_day private def update_work_day WorkDay.create_or_update(self.person, date) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bookyt_projects-0.19.7 | app/models/activity.rb |
bookyt_projects-0.19.6 | app/models/activity.rb |
bookyt_projects-0.19.5 | app/models/activity.rb |