Class: Checkoff::Internal::ProjectTiming
- Inherits:
-
Object
- Object
- Checkoff::Internal::ProjectTiming
- Defined in:
- lib/checkoff/internal/project_timing.rb
Overview
Utility methods for working with project dates and times
Instance Method Summary collapse
- #custom_field(project, custom_field_name) ⇒ Time, ...
- #date_or_time_field_by_name(project, field_name) ⇒ Date, ...
- #due_date(project) ⇒ Date?
-
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client:)) ⇒ ProjectTiming
constructor
A new instance of ProjectTiming.
- #start_date(project) ⇒ Date?
Constructor Details
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client:)) ⇒ ProjectTiming
Returns a new instance of ProjectTiming.
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, ...
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, ...
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?
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?
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 |