Class: MOCO::Employment
- Inherits:
-
BaseEntity
- Object
- BaseEntity
- MOCO::Employment
- Defined in:
- lib/moco/entities/employment.rb
Overview
Represents a MOCO user employment/work schedule record Access via: moco.employments.where(user_id: 123) or user.employments
Required attributes for create:
user_id - Integer, the user this employment belongs to
pattern - Hash, weekly work schedule:
{ "am": [0, 4, 4, 4, 4], "pm": [0, 4, 4, 4, 4] }
Arrays represent Mon-Fri morning/afternoon hours
Optional attributes:
from - String, "YYYY-MM-DD" when employment starts (default: today)
to - String, "YYYY-MM-DD" when employment ends (null = ongoing)
Read-only attributes:
id, weekly_target_hours, user (Hash), created_at, updated_at
Example:
# Create full-time employment (8h/day Mon-Fri)
moco.employments.create(
user_id: 123,
pattern: {
am: [4, 4, 4, 4, 4],
pm: [4, 4, 4, 4, 4]
},
from: "2024-01-01"
)
# Create part-time (4h/day Tue-Thu)
moco.employments.create(
user_id: 123,
pattern: {
am: [0, 4, 4, 4, 0],
pm: [0, 0, 0, 0, 0]
},
from: "2024-01-01"
)
Instance Attribute Summary
Attributes inherited from BaseEntity
Class Method Summary collapse
Instance Method Summary collapse
- #to_s ⇒ Object
-
#user ⇒ Object
Associations.
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_path ⇒ Object
42 43 44 |
# File 'lib/moco/entities/employment.rb', line 42 def self.entity_path "users/employments" end |
Instance Method Details
#to_s ⇒ Object
51 52 53 |
# File 'lib/moco/entities/employment.rb', line 51 def to_s "Employment ##{id} (#{from} - #{self.to || 'present'})" end |
#user ⇒ Object
Associations
47 48 49 |
# File 'lib/moco/entities/employment.rb', line 47 def user association(:user) end |