Class: AllHours::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/all_hours/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, api:) ⇒ Project

Returns a new instance of Project.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/all_hours/project.rb', line 27

def initialize data:, api:
  @api = api
  @canSyncTasks = data["canSyncTasks"]
  @user_ids = data["users"]
  @id = data["id"]
  @platform = data["platform"]
  @name = data["name"]
  @createdAt = Date.parse data["createdAt"]
  @workspaceId = data["workspaceId"]
  @workspaceName = data["workspaceName"]
  @hasWebhook = data["hasWebhook"]
  @status = data["status"]
  @estimatesType = data["estimatesType"]
  @budget = data["budget"]
  @enableResourcePlanner = data["enableResourcePlanner"]
  @isTemplate = data["isTemplate"]
  @privacy = data["privacy"]
  @client = data["client"]
  @favorite = data["favorite"]
  @foreign = data["foreign"]
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def api
  @api
end

#budgetObject

Returns the value of attribute budget.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def budget
  @budget
end

#canSyncTasksObject

Returns the value of attribute canSyncTasks.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def canSyncTasks
  @canSyncTasks
end

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def client
  @client
end

#createdAtObject

Returns the value of attribute createdAt.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def createdAt
  @createdAt
end

#enableResourcePlannerObject

Returns the value of attribute enableResourcePlanner.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def enableResourcePlanner
  @enableResourcePlanner
end

#estimatesTypeObject

Returns the value of attribute estimatesType.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def estimatesType
  @estimatesType
end

#favoriteObject

Returns the value of attribute favorite.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def favorite
  @favorite
end

#foreignObject

Returns the value of attribute foreign.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def foreign
  @foreign
end

#hasWebhookObject

Returns the value of attribute hasWebhook.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def hasWebhook
  @hasWebhook
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def id
  @id
end

#isTemplateObject

Returns the value of attribute isTemplate.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def isTemplate
  @isTemplate
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def name
  @name
end

#platformObject

Returns the value of attribute platform.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def platform
  @platform
end

#privacyObject

Returns the value of attribute privacy.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def privacy
  @privacy
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def status
  @status
end

#user_idsObject

Returns the value of attribute user_ids.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def user_ids
  @user_ids
end

#workspaceIdObject

Returns the value of attribute workspaceId.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def workspaceId
  @workspaceId
end

#workspaceNameObject

Returns the value of attribute workspaceName.



7
8
9
# File 'lib/all_hours/project.rb', line 7

def workspaceName
  @workspaceName
end

Class Method Details

.all(api:, limit: 200, query: nil, platform: nil) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/all_hours/project.rb', line 54

def self.all api:, limit: 200, query: nil, platform: nil
  data = api.api_call path: "projects", query: {limit: limit, query: query, platform: platform}
  projects = []
  data.each do |project_data|
    projects << Project.new(api: api, data: project_data)
  end

  projects
end

.find(api:, project_id:) ⇒ Object



49
50
51
52
# File 'lib/all_hours/project.rb', line 49

def self.find api:, project_id:
  data = api.api_call path: "projects/#{project_id}"
  Project.new api: api, data: data
end

Instance Method Details

#budgeted_minutesObject



80
81
82
# File 'lib/all_hours/project.rb', line 80

def budgeted_minutes
  budget.nil? ? 0 : budget["budget"] / 60
end

#percentage_usedObject



88
89
90
91
# File 'lib/all_hours/project.rb', line 88

def percentage_used
  return 0 unless budgeted_minutes&.positive? && remaining_minutes
  (((budgeted_minutes.to_f - remaining_minutes) / budgeted_minutes) * 100).round
end

#remaining_minutesObject



84
85
86
# File 'lib/all_hours/project.rb', line 84

def remaining_minutes
  budget.nil? ? 0 : budgeted_minutes - (budget["progress"] / 60)
end

#tasks(limit: 250, page: 1, excludeClosed: true, query: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/all_hours/project.rb', line 64

def tasks limit: 250, page: 1, excludeClosed: true, query: nil
  data = @api.api_call(path: "projects/#{@id}/tasks",
                       query: {limit: limit, page: page,
                               excludeClosed: excludeClosed, query: query})
  tasks = []
  data.each do |task_data|
    tasks << Task.new(api: api, data: task_data)
  end

  tasks
end

#urlObject



76
77
78
# File 'lib/all_hours/project.rb', line 76

def url
  "https://app.everhour.com/#/projects/#{id}"
end