Class: TimeDistribution::WorkDayCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/time_distribution/work_day_collection.rb

Constant Summary collapse

MONTHS =
[:january, :february, :march, :april, :may, :june, :july, :august, :september, :october, :november, :december]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*days, official_work_days: {}) ⇒ WorkDayCollection

Returns a new instance of WorkDayCollection.



26
27
28
29
30
31
32
33
# File 'lib/time_distribution/work_day_collection.rb', line 26

def initialize(*days, official_work_days: {})
  super(days)
  provide_methods_for_setting_work_days_in_months
  @official_work_days = official_work_days.dup
  MONTHS.each do |m|
    @official_work_days[m] ||= 0
  end
end

Instance Attribute Details

#official_work_daysObject (readonly)

> number of official work days in that month. Initialized to zero.



11
12
13
# File 'lib/time_distribution/work_day_collection.rb', line 11

def official_work_days
  @official_work_days
end

Instance Method Details

#avg_hours_per_day_worked(*subjects) ⇒ Object



56
57
58
# File 'lib/time_distribution/work_day_collection.rb', line 56

def avg_hours_per_day_worked(*subjects)
  hours(*subjects) / length.to_f
end

#avg_hours_per_official_work_day(*subjects) ⇒ Object



52
53
54
# File 'lib/time_distribution/work_day_collection.rb', line 52

def avg_hours_per_official_work_day(*subjects)
  hours(*subjects) / @official_work_days.values.inject(:+).to_f
end

#hours(*subjects) ⇒ Object



60
61
62
# File 'lib/time_distribution/work_day_collection.rb', line 60

def hours(*subjects)
  inject(0) { |sum, d| sum += d.to_hours(*subjects) }
end

#time_workedObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/time_distribution/work_day_collection.rb', line 35

def time_worked
  inject({}) do |hash, d|
    t = d.time_worked
    if t.respond_to?(:each_key)
      t.each_key do |key|
        hash[key] = Duration.new(0) unless hash[key]
        hash[key] += t[key]
      end
    else
      d_subject = d.tasks.first.subject
      hash[d_subject] = Duration.new(0) unless hash[d_subject]
      hash[d_subject] += t
    end
    hash
  end
end

#to_mdObject



64
65
66
# File 'lib/time_distribution/work_day_collection.rb', line 64

def to_md
  inject('') { |s, d| s += "#{d.to_md}\n" }
end

#to_ssvObject



68
69
70
# File 'lib/time_distribution/work_day_collection.rb', line 68

def to_ssv
  inject('') { |s, d| s += "#{d.to_ssv}" }
end