Class: Reclaim::Task
- Inherits:
-
Object
- Object
- Reclaim::Task
- 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
-
#always_private ⇒ Object
All task attributes with accessor methods.
-
#created_at ⇒ Object
All task attributes with accessor methods.
-
#deleted ⇒ Object
All task attributes with accessor methods.
-
#due_date ⇒ Object
All task attributes with accessor methods.
-
#duration ⇒ Object
All task attributes with accessor methods.
-
#event_category ⇒ Object
All task attributes with accessor methods.
-
#event_color ⇒ Object
All task attributes with accessor methods.
-
#id ⇒ Object
All task attributes with accessor methods.
-
#max_chunk_size ⇒ Object
All task attributes with accessor methods.
-
#max_work_duration ⇒ Object
All task attributes with accessor methods.
-
#min_chunk_size ⇒ Object
All task attributes with accessor methods.
-
#min_work_duration ⇒ Object
All task attributes with accessor methods.
-
#notes ⇒ Object
All task attributes with accessor methods.
-
#priority ⇒ Object
All task attributes with accessor methods.
-
#snooze_until ⇒ Object
All task attributes with accessor methods.
-
#start ⇒ Object
All task attributes with accessor methods.
-
#status ⇒ Object
All task attributes with accessor methods.
-
#time_scheme_id ⇒ Object
All task attributes with accessor methods.
-
#title ⇒ Object
All task attributes with accessor methods.
-
#updated_at ⇒ Object
All task attributes with accessor methods.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Check if task is active (not deleted and not archived/cancelled).
-
#completed? ⇒ Boolean
Check if task is completed.
-
#due_date_formatted ⇒ Object
Get formatted due date string.
-
#initialize(attributes = {}) ⇒ Task
constructor
A new instance of Task.
-
#overdue? ⇒ Boolean
Check if task is overdue.
-
#priority_symbol ⇒ Object
Get priority as symbol.
-
#to_h ⇒ Object
Convert task to hash for API requests.
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_private ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def always_private @always_private end |
#created_at ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def created_at @created_at end |
#deleted ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def deleted @deleted end |
#due_date ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def due_date @due_date end |
#duration ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def duration @duration end |
#event_category ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def event_category @event_category end |
#event_color ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def event_color @event_color end |
#id ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def id @id end |
#max_chunk_size ⇒ Object
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_duration ⇒ Object
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_size ⇒ Object
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_duration ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def min_work_duration @min_work_duration end |
#notes ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def notes @notes end |
#priority ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def priority @priority end |
#snooze_until ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def snooze_until @snooze_until end |
#start ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def start @start end |
#status ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def status @status end |
#time_scheme_id ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def time_scheme_id @time_scheme_id end |
#title ⇒ Object
All task attributes with accessor methods
25 26 27 |
# File 'lib/reclaim/task.rb', line 25 def title @title end |
#updated_at ⇒ Object
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)
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
102 103 104 |
# File 'lib/reclaim/task.rb', line 102 def completed? %w[COMPLETE ARCHIVED].include?(status) end |
#due_date_formatted ⇒ Object
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
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_symbol ⇒ Object
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_h ⇒ Object
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 |