Class: Checkoff::Internal::TaskTiming
- Inherits:
-
Object
- Object
- Checkoff::Internal::TaskTiming
- Defined in:
- lib/checkoff/internal/task_timing.rb
Overview
Utility methods for working with task dates and times
Instance Method Summary collapse
- #custom_field(task, custom_field_name) ⇒ Time, ...
- #date_or_time_field_by_name(task, field_name) ⇒ Date, ...
- #due_date_or_time(task) ⇒ Date, ...
-
#due_time(task) ⇒ Time?
@sg-ignore.
-
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client:)) ⇒ TaskTiming
constructor
A new instance of TaskTiming.
- #modified_time(task) ⇒ Time?
- #start_date_or_time(task) ⇒ Date, ...
-
#start_time(task) ⇒ Time?
@sg-ignore.
Constructor Details
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client:)) ⇒ TaskTiming
Returns a new instance of TaskTiming.
12 13 14 15 16 17 18 |
# File 'lib/checkoff/internal/task_timing.rb', line 12 def initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client:)) @time_class = time_class @date_class = date_class @custom_fields = custom_fields end |
Instance Method Details
#custom_field(task, custom_field_name) ⇒ Time, ...
68 69 70 71 72 73 74 75 |
# File 'lib/checkoff/internal/task_timing.rb', line 68 def custom_field(task, custom_field_name) custom_field = @custom_fields.resource_custom_field_by_name_or_raise(task, custom_field_name) # @type [String, nil] time_str = custom_field.fetch('display_value') return nil if time_str.nil? Time.parse(time_str) end |
#date_or_time_field_by_name(task, field_name) ⇒ Date, ...
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/checkoff/internal/task_timing.rb', line 81 def date_or_time_field_by_name(task, field_name) return due_date_or_time(task) if field_name == :due return start_date_or_time(task) if field_name == :start return modified_time(task) if field_name == :modified return start_date_or_time(task) || due_date_or_time(task) if field_name == :ready if field_name.is_a?(Array) # @type [Symbol] actual_field_name = field_name.first args = field_name[1..] return custom_field(task, *args) if actual_field_name == :custom_field end raise "Teach me how to handle field #{field_name.inspect}" end |
#due_date_or_time(task) ⇒ Date, ...
49 50 51 52 53 54 55 |
# File 'lib/checkoff/internal/task_timing.rb', line 49 def due_date_or_time(task) return @time_class.parse(T.must(task.due_at)).localtime unless task.due_at.nil? return @date_class.parse(task.due_on) unless task.due_on.nil? nil end |
#due_time(task) ⇒ Time?
@sg-ignore
30 31 32 |
# File 'lib/checkoff/internal/task_timing.rb', line 30 def due_time(task) date_or_time_field_by_name(task, :due)&.to_time end |
#modified_time(task) ⇒ Time?
60 61 62 |
# File 'lib/checkoff/internal/task_timing.rb', line 60 def modified_time(task) @time_class.parse(task.modified_at).localtime unless task.modified_at.nil? end |
#start_date_or_time(task) ⇒ Date, ...
37 38 39 40 41 42 43 44 |
# File 'lib/checkoff/internal/task_timing.rb', line 37 def start_date_or_time(task) # @sg-ignore return @time_class.parse(task.start_at).localtime unless task.start_at.nil? return @date_class.parse(task.start_on) unless task.start_on.nil? nil end |
#start_time(task) ⇒ Time?
@sg-ignore
23 24 25 |
# File 'lib/checkoff/internal/task_timing.rb', line 23 def start_time(task) date_or_time_field_by_name(task, :start)&.to_time end |