Module: EffectiveWorkExperienceUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_work_experience_user.rb
Overview
EffectiveWorkExperienceUser
Mark your user model with effective_work_experience_user to get the work experience associations and the hours calculations used by the records, summaries and reports.
Requires a work_experience_mentor_id column on your users table.
Your user model may also define:
- supervisor the user responsible for this intern's day to day work
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
-
#work_experience_hours(month:, work_experience_subcategory: nil) ⇒ Object
One subcategory and month.
-
#work_experience_hours_by_year(year:, work_experience_subcategory: nil) ⇒ Object
One subcategory for every month in this year.
- #work_experience_intern? ⇒ Boolean
- #work_experience_mentor? ⇒ Boolean
-
#work_experience_outside_mentor? ⇒ Boolean
This intern's mentor does not have an account.
- #work_experience_subcategories ⇒ Object
-
#work_experience_total_hours_to_date(month:, work_experience_subcategory: nil) ⇒ Object
One subcategory for all months up to and including this month.
Instance Method Details
#work_experience_hours(month:, work_experience_subcategory: nil) ⇒ Object
One subcategory and month
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/concerns/effective_work_experience_user.rb', line 87 def work_experience_hours(month:, work_experience_subcategory: nil) work_experience_record = work_experience_records.find { |record| record.month == month } return 0.0 if work_experience_record.blank? hours = if work_experience_subcategory.present? work_experience_record.work_experience_entry(work_experience_subcategory: work_experience_subcategory).hours else work_experience_record.work_experience_entries.sum { |work_experience_entry| work_experience_entry.hours } end hours.round(2) end |
#work_experience_hours_by_year(year:, work_experience_subcategory: nil) ⇒ Object
One subcategory for every month in this year
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/concerns/effective_work_experience_user.rb', line 101 def work_experience_hours_by_year(year:, work_experience_subcategory: nil) work_experience_records_in_year = work_experience_records.select { |record| record.month.present? && record.month.year == year } return 0.0 if work_experience_records_in_year.blank? hours = if work_experience_subcategory.present? work_experience_records_in_year.sum { |record| record.work_experience_entry(work_experience_subcategory: work_experience_subcategory).hours } else work_experience_records_in_year.sum { |record| record.work_experience_entries.sum { |work_experience_entry| work_experience_entry.hours } } end hours.round(2) end |
#work_experience_intern? ⇒ Boolean
68 69 70 71 |
# File 'app/models/concerns/effective_work_experience_user.rb', line 68 def work_experience_intern? return true if try(:intern?) work_experience_records.present? || work_experience_summaries.present? end |
#work_experience_mentor? ⇒ Boolean
73 74 75 |
# File 'app/models/concerns/effective_work_experience_user.rb', line 73 def work_experience_mentor? work_experience_mentees.present? || mentee_work_experience_summaries.present? end |
#work_experience_outside_mentor? ⇒ Boolean
This intern's mentor does not have an account. Their summaries are reviewed automatically.
78 79 80 |
# File 'app/models/concerns/effective_work_experience_user.rb', line 78 def work_experience_outside_mentor? work_experience_outside_mentor.present? end |
#work_experience_subcategories ⇒ Object
82 83 84 |
# File 'app/models/concerns/effective_work_experience_user.rb', line 82 def work_experience_subcategories @work_experience_subcategories ||= Effective::WorkExperienceSubcategory.all.sorted end |
#work_experience_total_hours_to_date(month:, work_experience_subcategory: nil) ⇒ Object
One subcategory for all months up to and including this month
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/models/concerns/effective_work_experience_user.rb', line 115 def work_experience_total_hours_to_date(month:, work_experience_subcategory: nil) work_experience_records_to_date = if month.blank? work_experience_records.select { |record| record.backdated? } else work_experience_records.select { |record| record.backdated? || record.month <= month } end return 0.0 if work_experience_records_to_date.blank? hours = work_experience_records_to_date.sum do |work_experience_record| if work_experience_subcategory.present? work_experience_record.work_experience_entry(work_experience_subcategory: work_experience_subcategory).hours else work_experience_record.work_experience_entries.sum { |work_experience_entry| work_experience_entry.hours } end end hours.round(2) end |