Class: Checkoff::Internal::TaskTiming
- Inherits:
-
Object
- Object
- Checkoff::Internal::TaskTiming
- Defined in:
- lib/checkoff/internal/task_timing.rb,
sig/checkoff.rbs
Overview
Utility methods for working with task dates and times
Instance Method Summary collapse
-
#custom_field(task, custom_field_name) ⇒ Time, ...
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#date_or_time_field_by_name(task, field_name) ⇒ Date, ...
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#due_date_or_time(task) ⇒ Date, ...
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#due_time(task) ⇒ Time?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client:)) ⇒ Object
constructor
sord warn - Asana::Client wasn't able to be resolved to a constant in this project @param
time_class. -
#modified_time(task) ⇒ Time?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#start_date_or_time(task) ⇒ Date, ...
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#start_time(task) ⇒ Time?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task.
Constructor Details
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client:)) ⇒ Object
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
@param time_class
@param date_class
@param client
@param custom_fields
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, ...
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
@param custom_field_name
65 66 67 68 69 70 71 72 |
# File 'lib/checkoff/internal/task_timing.rb', line 65 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, ...
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
@param field_name
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/checkoff/internal/task_timing.rb', line 78 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, ...
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
46 47 48 49 50 51 52 |
# File 'lib/checkoff/internal/task_timing.rb', line 46 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?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
28 29 30 |
# File 'lib/checkoff/internal/task_timing.rb', line 28 def due_time(task) date_or_time_field_by_name(task, :due)&.to_time end |
#modified_time(task) ⇒ Time?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
57 58 59 |
# File 'lib/checkoff/internal/task_timing.rb', line 57 def modified_time(task) @time_class.parse(T.must(task.modified_at)).localtime unless task.modified_at.nil? end |
#start_date_or_time(task) ⇒ Date, ...
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
35 36 37 38 39 40 41 |
# File 'lib/checkoff/internal/task_timing.rb', line 35 def start_date_or_time(task) return @time_class.parse(T.must(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?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
22 23 24 |
# File 'lib/checkoff/internal/task_timing.rb', line 22 def start_time(task) date_or_time_field_by_name(task, :start)&.to_time end |