Class: MOCO::Presence

Inherits:
BaseEntity show all
Defined in:
lib/moco/entities/presence.rb

Overview

Represents a MOCO presence entry (work time tracking)

Required attributes for create:

date - String, "YYYY-MM-DD" date
from - String, "HH:MM" start time (e.g., "08:00")

Optional attributes:

to            - String, "HH:MM" end time (e.g., "17:00"), can be blank for open entry
is_home_office - Boolean, whether working from home (default: false)

Read-only attributes:

id, user (Hash), created_at, updated_at

Class methods:

Presence.touch(client) - Clock in/out (creates or closes presence)

Example:

# Log work time
moco.presences.create(
  date: "2024-01-15",
  from: "09:00",
  to: "17:30"
)

# Start work (open-ended)
moco.presences.create(
  date: "2024-01-16",
  from: "08:30",
  is_home_office: true
)

# Clock in/out via touch
MOCO::Presence.touch(moco)

Instance Attribute Summary

Attributes inherited from BaseEntity

#attributes, #client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseEntity

#==, #association, #destroy, #eql?, #has_many, #hash, #id, #initialize, #inspect, #reload, #save, #to_h, #to_json, #update

Constructor Details

This class inherits a constructor from MOCO::BaseEntity

Class Method Details

.entity_pathObject

Define the specific API path for this entity as a class method



40
41
42
# File 'lib/moco/entities/presence.rb', line 40

def self.entity_path
  "users/presences"
end

.touch(client, is_home_office: false, override: nil) ⇒ Object

Class methods for special operations



45
46
47
48
49
50
51
# File 'lib/moco/entities/presence.rb', line 45

def self.touch(client, is_home_office: false, override: nil)
  payload = {}
  payload[:is_home_office] = is_home_office if is_home_office
  payload[:override] = override if override

  client.post("users/presences/touch", payload)
end

Instance Method Details

#to_sObject



58
59
60
# File 'lib/moco/entities/presence.rb', line 58

def to_s
  "#{date} - #{from} to #{to} - #{user&.full_name}"
end

#userObject

Associations



54
55
56
# File 'lib/moco/entities/presence.rb', line 54

def user
  @user ||= client.users.find(user_id) if user_id
end