You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
954 B

class Entry < ApplicationRecord
belongs_to :user
validates :date, :hours, :minutes, presence: true
validates :hours, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :minutes, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than: 60 }
before_save :normalize_time
PRAKTIKUMSTYPEN = %w[propädeutikum fachspezifikum]
ENTRY_ARTEN = %w[Praktikum Selbsterfahrung Supervision]
validates :praktikums_typ, inclusion: { in: PRAKTIKUMSTYPEN }
validates :entry_art, inclusion: { in: ENTRY_ARTEN }
validates :distance_km, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
def kilometer_pauschale
return 0 unless distance_km.present?
distance_km * 0.42
end
def jahr
date.year
end
def total_minutes
hours * 60 + minutes
end
private
def normalize_time
self.hours += minutes / 60
self.minutes = minutes % 60
end
end