Class: WeeklyTimeReport
- Inherits:
-
Object
- Object
- WeeklyTimeReport
- Defined in:
- app/models/weekly_time_report.rb
Overview
Get internal/external hour split for a given week
Instance Method Summary collapse
- #get_weekly_hours(date) ⇒ Object
-
#initialize(date_in_week = Time.zone.now, partial_week = false) ⇒ WeeklyTimeReport
constructor
A new instance of WeeklyTimeReport.
- #run ⇒ Object
- #sum_hours(method, hours) ⇒ Object
Constructor Details
#initialize(date_in_week = Time.zone.now, partial_week = false) ⇒ WeeklyTimeReport
Returns a new instance of WeeklyTimeReport.
3 4 5 6 |
# File 'app/models/weekly_time_report.rb', line 3 def initialize(date_in_week=Time.zone.now, partial_week=false) @date = date_in_week @partial_week = partial_week end |
Instance Method Details
#get_weekly_hours(date) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/weekly_time_report.rb', line 16 def get_weekly_hours(date) start_date = date.beginning_of_week.to_date if @partial_week end_date = date else end_date = date.end_of_week.to_date end work_units = WorkUnit.scheduled_between(start_date, end_date) { external: sum_hours(:external?, work_units).to_i, internal: sum_hours(:internal?, work_units).to_i } end |
#run ⇒ Object
8 9 10 |
# File 'app/models/weekly_time_report.rb', line 8 def run get_weekly_hours(@date) end |
#sum_hours(method, hours) ⇒ Object
12 13 14 |
# File 'app/models/weekly_time_report.rb', line 12 def sum_hours(method, hours) hours.select{|wu| wu.send(method) }.sum(&:hours) end |