Sha256: db57e74245853ccab4860a99f7fdc33a69e0f815e13d1ef803a12b3002cde2d4
Contents?: true
Size: 940 Bytes
Versions: 6
Compression:
Stored size: 940 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 before_save :update_work_day private def update_work_day WorkDay.create_or_update_upto(self.person, date) end end
Version data entries
6 entries across 6 versions & 1 rubygems