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, ...
@sg-ignore.
-
#due_date_or_time(task) ⇒ Date, ...
@sg-ignore.
- #due_time(task) ⇒ Time?
-
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client: client)) ⇒ TaskTiming
constructor
A new instance of TaskTiming.
- #modified_time(task) ⇒ Time?
-
#start_date_or_time(task) ⇒ Date, ...
@sg-ignore.
- #start_time(task) ⇒ Time?
Constructor Details
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client: client)) ⇒ TaskTiming
Returns a new instance of TaskTiming.
11 12 13 14 15 16 17 |
# File 'lib/checkoff/internal/task_timing.rb', line 11 def initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client: 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 76 |
# 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) # @sg-ignore # @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, ...
@sg-ignore
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/checkoff/internal/task_timing.rb', line 83 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) # @sg-ignore # @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, ...
@sg-ignore
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(task.due_at) unless task.due_at.nil? return @date_class.parse(task.due_on) unless task.due_on.nil? nil end |
#due_time(task) ⇒ Time?
27 28 29 |
# File 'lib/checkoff/internal/task_timing.rb', line 27 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) unless task.modified_at.nil? end |
#start_date_or_time(task) ⇒ Date, ...
@sg-ignore
36 37 38 39 40 41 42 |
# File 'lib/checkoff/internal/task_timing.rb', line 36 def start_date_or_time(task) return @time_class.parse(task.start_at) unless task.start_at.nil? return @date_class.parse(task.start_on) unless task.start_on.nil? nil end |
#start_time(task) ⇒ Time?
21 22 23 |
# File 'lib/checkoff/internal/task_timing.rb', line 21 def start_time(task) date_or_time_field_by_name(task, :start)&.to_time end |