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, ...
@sg-ignore.
-
#due_date(project) ⇒ Date?
@sg-ignore.
-
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client: client)) ⇒ ProjectTiming
constructor
A new instance of ProjectTiming.
-
#start_date(project) ⇒ Date?
@sg-ignore.
Constructor Details
#initialize(time_class: Time, date_class: Date, client: Checkoff::Clients.new.client, custom_fields: Checkoff::CustomFields.new(client: client)) ⇒ ProjectTiming
Returns a new instance of ProjectTiming.
13 14 15 16 17 18 19 |
# File 'lib/checkoff/internal/project_timing.rb', line 13 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(project, custom_field_name) ⇒ Time, ...
47 48 49 50 51 52 53 54 55 |
# File 'lib/checkoff/internal/project_timing.rb', line 47 def custom_field(project, custom_field_name) custom_field = @custom_fields.resource_custom_field_by_name_or_raise(project, 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(project, field_name) ⇒ Date, ...
@sg-ignore
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/checkoff/internal/project_timing.rb', line 62 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) # @sg-ignore # @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?
@sg-ignore
37 38 39 40 41 |
# File 'lib/checkoff/internal/project_timing.rb', line 37 def due_date(project) return @date_class.parse(project.due_on) unless project.due_on.nil? nil end |
#start_date(project) ⇒ Date?
@sg-ignore
26 27 28 29 30 |
# File 'lib/checkoff/internal/project_timing.rb', line 26 def start_date(project) return @date_class.parse(project.start_on) unless project.start_on.nil? nil end |