Class: Forecast::API::Assignments

Inherits:
Base
  • Object
show all
Includes:
Behavior::Crud
Defined in:
lib/forecast/api/assignments.rb

Instance Attribute Summary

Attributes inherited from Base

#credentials

Instance Method Summary collapse

Methods included from Behavior::Crud

#all, #find

Methods inherited from Base

api_model, #initialize

Constructor Details

This class inherits a constructor from Forecast::API::Base

Instance Method Details

#business_days_between(date1, date2) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/forecast/api/assignments.rb', line 51

def business_days_between(date1, date2)
  business_days = 0
  date = date2
  while date > date1
   business_days = business_days + 1 unless date.saturday? or date.sunday?
   date = date - 1.day
  end
  business_days
end

#by_project(project_id, query_options = {}) ⇒ Object



12
13
14
15
# File 'lib/forecast/api/assignments.rb', line 12

def by_project(project_id, query_options={})
  query = {project_id: project_id}.merge(query_options)
  self.all(query)
end

#createObject



40
# File 'lib/forecast/api/assignments.rb', line 40

def create(*) ; raise "not implemented" ; end

#deleteObject



42
# File 'lib/forecast/api/assignments.rb', line 42

def delete(*) ; raise "not implemented" ; end

#last_by_date(array_hm) ⇒ Object



45
46
47
48
49
# File 'lib/forecast/api/assignments.rb', line 45

def last_by_date(array_hm)
  array_hm.sort_by do |x|
    Date.strptime(x.end_date, FORECAST_DATE_FORMAT)
  end.last
end

#last_by_project(project_id) ⇒ Object



34
35
36
37
# File 'lib/forecast/api/assignments.rb', line 34

def last_by_project(project_id)
  x = self.by_project(project_id)
  self.last_by_date(x)
end

#sum_allocation_seconds(query) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/forecast/api/assignments.rb', line 17

def sum_allocation_seconds(query)
  axs = self.all(query)

  total_time = 0

  axs.each do |x|
    start_date = Date.strptime(x.start_date, FORECAST_DATE_FORMAT)
    end_date = Date.strptime(x.end_date, FORECAST_DATE_FORMAT)

    num_days = start_date.business_days_until(end_date) + 1

    total_time += (1.0 * x.allocation * num_days)
  end

  return total_time
end

#updateObject



41
# File 'lib/forecast/api/assignments.rb', line 41

def update(*) ; raise "not implemented" ; end