Class: Checkoff::Internal::ProjectTiming
- Inherits:
-
Object
- Object
- Checkoff::Internal::ProjectTiming
- Defined in:
- lib/checkoff/internal/project_timing.rb,
sig/checkoff.rbs
Overview
Utility methods for working with project dates and times
Instance Method Summary collapse
-
#custom_field(project, custom_field_name) ⇒ Time, ...
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param
project. -
#date_or_time_field_by_name(project, field_name) ⇒ Date, ...
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param
project. -
#due_date(project) ⇒ Date?
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param
project. -
#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. -
#start_date(project) ⇒ Date?
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param
project.
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
14 15 16 17 18 19 20 |
# File 'lib/checkoff/internal/project_timing.rb', line 14 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(project, custom_field_name) ⇒ Time, ...
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
@param project
@param custom_field_name
44 45 46 47 48 49 50 51 |
# File 'lib/checkoff/internal/project_timing.rb', line 44 def custom_field(project, custom_field_name) custom_field = @custom_fields.resource_custom_field_by_name_or_raise(project, 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(project, field_name) ⇒ Date, ...
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
@param project
@param field_name
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/checkoff/internal/project_timing.rb', line 57 def date_or_time_field_by_name(project, field_name) return due_date(project) if field_name == :due return start_date(project) if field_name == :start return start_date(project) 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(project, *args) if actual_field_name == :custom_field end raise "Teach me how to handle field #{field_name.inspect}" end |
#due_date(project) ⇒ Date?
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
@param project
34 35 36 37 38 |
# File 'lib/checkoff/internal/project_timing.rb', line 34 def due_date(project) return @date_class.parse(project.due_on) unless project.due_on.nil? nil end |
#start_date(project) ⇒ Date?
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
@param project
25 26 27 28 29 |
# File 'lib/checkoff/internal/project_timing.rb', line 25 def start_date(project) return @date_class.parse(project.start_on) unless project.start_on.nil? nil end |