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:)) ⇒ 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:)) ⇒ 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, ...
67 68 69 70 71 72 73 74 75 |
# File 'lib/checkoff/internal/task_timing.rb', line 67 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
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/checkoff/internal/task_timing.rb', line 82 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
48 49 50 51 52 53 54 |
# File 'lib/checkoff/internal/task_timing.rb', line 48 def due_date_or_time(task) return @time_class.parse(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?
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?
59 60 61 |
# File 'lib/checkoff/internal/task_timing.rb', line 59 def modified_time(task) @time_class.parse(task.modified_at).localtime 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).localtime unless task.start_at.nil? return @date_class.parse(task.start_on) unless task.start_on.nil? nil end |
#start_time(task) ⇒ Time?
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 |