Class: MOCO::Activity
- Inherits:
-
BaseEntity
- Object
- BaseEntity
- MOCO::Activity
- Defined in:
- lib/moco/entities.rb,
lib/moco/entities/activity.rb
Overview
Represents a MOCO activity (time entry) Provides methods for activity-specific operations and associations
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#billable ⇒ Object
Returns the value of attribute billable.
-
#billed ⇒ Object
Returns the value of attribute billed.
-
#customer ⇒ Object
Fetches the associated Customer (Company) object.
-
#date ⇒ Object
Returns the value of attribute date.
-
#description ⇒ Object
Returns the value of attribute description.
-
#hours ⇒ Object
Returns the value of attribute hours.
-
#id ⇒ Object
Returns the value of attribute id.
-
#project ⇒ Object
Associations Fetches the associated Project object.
-
#seconds ⇒ Object
Returns the value of attribute seconds.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#task ⇒ Object
Fetches the associated Task object.
-
#user ⇒ Object
Fetches the associated User object.
Attributes inherited from BaseEntity
Class Method Summary collapse
- .bulk_create(client, activities) ⇒ Object
-
.disregard(client, reason:, activity_ids:, company_id:, project_id: nil) ⇒ Object
Class methods for bulk operations.
Instance Method Summary collapse
-
#remote_id ⇒ Object
Access the remote_id attribute.
-
#start_timer ⇒ Object
Instance methods for activity-specific operations.
- #stop_timer ⇒ Object
- #to_s ⇒ Object
Methods inherited from BaseEntity
#==, #association, #destroy, #eql?, #has_many, #hash, #initialize, #inspect, #reload, #save, #to_h, #to_json, #update
Constructor Details
This class inherits a constructor from MOCO::BaseEntity
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def active @active end |
#billable ⇒ Object
Returns the value of attribute billable.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def billable @billable end |
#billed ⇒ Object
Returns the value of attribute billed.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def billed @billed end |
#customer ⇒ Object
Fetches the associated Customer (Company) object.
80 81 82 |
# File 'lib/moco/entities/activity.rb', line 80 def customer @customer end |
#date ⇒ Object
Returns the value of attribute date.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def date @date end |
#description ⇒ Object
Returns the value of attribute description.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def description @description end |
#hours ⇒ Object
Returns the value of attribute hours.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def hours @hours end |
#id ⇒ Object
Returns the value of attribute id.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def id @id end |
#project ⇒ Object
Associations Fetches the associated Project object.
41 42 43 |
# File 'lib/moco/entities/activity.rb', line 41 def project @project end |
#seconds ⇒ Object
Returns the value of attribute seconds.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def seconds @seconds end |
#tag ⇒ Object
Returns the value of attribute tag.
70 71 72 |
# File 'lib/moco/entities.rb', line 70 def tag @tag end |
#task ⇒ Object
Fetches the associated Task object.
56 57 58 |
# File 'lib/moco/entities/activity.rb', line 56 def task @task end |
#user ⇒ Object
Fetches the associated User object.
68 69 70 |
# File 'lib/moco/entities/activity.rb', line 68 def user @user end |
Class Method Details
.bulk_create(client, activities) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/moco/entities/activity.rb', line 29 def self.bulk_create(client, activities) api_entities = activities.map do |activity| activity.to_h.except(:id, :project, :user, :customer).tap do |h| h[:project_id] = activity.project.id if activity.project h[:task_id] = activity.task.id if activity.task end end client.post("activities/bulk", { activities: api_entities }) end |
.disregard(client, reason:, activity_ids:, company_id:, project_id: nil) ⇒ Object
Class methods for bulk operations
19 20 21 22 23 24 25 26 27 |
# File 'lib/moco/entities/activity.rb', line 19 def self.disregard(client, reason:, activity_ids:, company_id:, project_id: nil) payload = { reason:, activity_ids:, company_id: } payload[:project_id] = project_id if project_id client.post("activities/disregard", payload) end |
Instance Method Details
#remote_id ⇒ Object
Access the remote_id attribute
93 94 95 |
# File 'lib/moco/entities/activity.rb', line 93 def remote_id attributes[:remote_id] end |
#start_timer ⇒ Object
Instance methods for activity-specific operations
8 9 10 11 |
# File 'lib/moco/entities/activity.rb', line 8 def start_timer client.patch("activities/#{id}/start_timer") self end |
#stop_timer ⇒ Object
13 14 15 16 |
# File 'lib/moco/entities/activity.rb', line 13 def stop_timer client.patch("activities/#{id}/stop_timer") self end |
#to_s ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/moco/entities.rb', line 73 def to_s description_part = description.empty? ? "" : " (#{description})" status_part = "(#{%i[billable billed].map { |x| (send(x) ? "" : "not ") + x.to_s }.join(", ")})" "#{date} - #{Helpers.decimal_hours_to_civil(hours)}h (#{seconds}s) - " \ "#{project&.name} - #{task&.name}#{description_part} #{status_part}" end |