Class: Reclaim::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/reclaim/task.rb

Overview

Represents a Reclaim task with all its properties and methods

Constant Summary collapse

PRIORITIES =

Task priority levels matching Reclaim API

{
  p1: 'P1',
  p2: 'P2',
  p3: 'P3',
  p4: 'P4'
}.freeze
STATUSES =

Task status values

%w[
  NEW SCHEDULED IN_PROGRESS COMPLETE ARCHIVED CANCELLED
].freeze
EVENT_COLORS =

Event colors for calendar display

%w[
  BLUE GREEN YELLOW ORANGE RED PURPLE PINK BROWN GRAY
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Task

Returns a new instance of Task.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/reclaim/task.rb', line 31

def initialize(attributes = {})
  # Convert API field names to internal format
  converted_attrs = {}
  attributes.each do |key, value|
    case key.to_s
    when 'timeChunksRequired'
      converted_attrs['duration'] = (value / 4.0) # Convert from 15-min chunks to hours
    when 'timeSchemeId'
      converted_attrs['time_scheme_id'] = value
    when 'alwaysPrivate'
      converted_attrs['always_private'] = value
    when 'eventCategory'
      converted_attrs['event_category'] = value
    when 'eventColor'
      converted_attrs['event_color'] = value
    when 'minChunkSize'
      converted_attrs['min_chunk_size'] = (value / 4.0) if value
    when 'maxChunkSize'
      converted_attrs['max_chunk_size'] = (value / 4.0) if value
    when 'due'
      converted_attrs['due_date'] = value
    else
      converted_attrs[key.to_s] = value
    end
  end

  converted_attrs.each do |key, value|
    setter = "#{key}="
    public_send(setter, value) if respond_to?(setter)
  end

  # Set defaults
  @priority ||= :p3
  @duration ||= 1.0
  @always_private ||= false
  @deleted ||= false
  @status ||= 'NEW'
end

Instance Attribute Details

#always_privateObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def always_private
  @always_private
end

#created_atObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def created_at
  @created_at
end

#deletedObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def deleted
  @deleted
end

#due_dateObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def due_date
  @due_date
end

#durationObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def duration
  @duration
end

#event_categoryObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def event_category
  @event_category
end

#event_colorObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def event_color
  @event_color
end

#idObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def id
  @id
end

#max_chunk_sizeObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def max_chunk_size
  @max_chunk_size
end

#max_work_durationObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def max_work_duration
  @max_work_duration
end

#min_chunk_sizeObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def min_chunk_size
  @min_chunk_size
end

#min_work_durationObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def min_work_duration
  @min_work_duration
end

#notesObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def notes
  @notes
end

#priorityObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def priority
  @priority
end

#snooze_untilObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def snooze_until
  @snooze_until
end

#startObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def start
  @start
end

#statusObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def status
  @status
end

#time_scheme_idObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def time_scheme_id
  @time_scheme_id
end

#titleObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def title
  @title
end

#updated_atObject

All task attributes with accessor methods



25
26
27
# File 'lib/reclaim/task.rb', line 25

def updated_at
  @updated_at
end

Instance Method Details

#active?Boolean

Check if task is active (not deleted and not archived/cancelled)

Returns:



97
98
99
# File 'lib/reclaim/task.rb', line 97

def active?
  !deleted && !%w[ARCHIVED CANCELLED].include?(status)
end

#completed?Boolean

Check if task is completed

Returns:



102
103
104
# File 'lib/reclaim/task.rb', line 102

def completed?
  %w[COMPLETE ARCHIVED].include?(status)
end

#due_date_formattedObject

Get formatted due date string



115
116
117
118
119
120
# File 'lib/reclaim/task.rb', line 115

def due_date_formatted
  return nil unless due_date

  parsed = parse_datetime(due_date)
  parsed&.strftime('%Y-%m-%d %H:%M')
end

#overdue?Boolean

Check if task is overdue

Returns:



107
108
109
110
111
112
# File 'lib/reclaim/task.rb', line 107

def overdue?
  return false unless due_date && active?

  due_time = parse_datetime(due_date)
  due_time && due_time < Time.now
end

#priority_symbolObject

Get priority as symbol



123
124
125
126
127
128
129
130
131
# File 'lib/reclaim/task.rb', line 123

def priority_symbol
  case priority
  when 'P1' then :p1
  when 'P2' then :p2
  when 'P3' then :p3
  when 'P4' then :p4
  else :p3
  end
end

#to_hObject

Convert task to hash for API requests



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/reclaim/task.rb', line 71

def to_h
  {
    id: id,
    title: title,
    notes: notes,
    due_date: due_date,
    priority: priority_for_api,
    duration: duration,
    min_chunk_size: min_chunk_size,
    max_chunk_size: max_chunk_size,
    min_work_duration: min_work_duration,
    max_work_duration: max_work_duration,
    snooze_until: snooze_until,
    start: start,
    time_scheme_id: time_scheme_id,
    always_private: always_private,
    event_category: event_category,
    event_color: event_color,
    status: status,
    created_at: created_at,
    updated_at: updated_at,
    deleted: deleted
  }.compact
end