Class: Checkoff::Internal::TaskHashes
- Inherits:
-
Object
- Object
- Checkoff::Internal::TaskHashes
- Defined in:
- lib/checkoff/internal/task_hashes.rb,
sig/checkoff.rbs
Overview
Builds on the standard API representation of an Asana task with some convenience keys.
Instance Method Summary collapse
-
#add_user_task_list(task_hash, memberships) ⇒ void
@param
task_hash. -
#h_to_task(task_data, client:) ⇒ Asana::Resources::Task
sord warn - Asana::Client wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task_data. -
#task_to_h(task) ⇒ ::Hash[untyped, untyped]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#unwrap_all_memberships(task_hash) ⇒ void
@param
task_hash. -
#unwrap_custom_fields(task_hash) ⇒ void
@param
task_hash. -
#unwrap_memberships(task_hash, memberships, resource, key) ⇒ Object
@param
task_hash.
Instance Method Details
#add_user_task_list(task_hash, memberships) ⇒ void
This method returns an undefined value.
@param task_hash
@param memberships
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/checkoff/internal/task_hashes.rb', line 52 def add_user_task_list(task_hash, memberships) return unless task_hash.key? 'assignee_section' assignee_section = task_hash.fetch('assignee_section') # @type [Hash{String => String}] assignee = T.cast(task_hash.fetch('assignee'), T::Hash[String, String]) memberships << { 'section' => assignee_section.dup, 'project' => { 'gid' => assignee.fetch('gid'), 'name' => :my_tasks, }, } end |
#h_to_task(task_data, client:) ⇒ Asana::Resources::Task
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task_data
@param client
25 26 27 28 29 30 |
# File 'lib/checkoff/internal/task_hashes.rb', line 25 def h_to_task(task_data, client:) # copy of task_data without the 'unwrapped' key clean_task_data = task_data.dup clean_task_data.delete('unwrapped') Asana::Resources::Task.new(clean_task_data, client:) end |
#task_to_h(task) ⇒ ::Hash[untyped, untyped]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
11 12 13 14 15 16 17 18 19 |
# File 'lib/checkoff/internal/task_hashes.rb', line 11 def task_to_h(task) # @type [Hash] task_hash = task.to_h task_hash['unwrapped'] = {} unwrap_custom_fields(task_hash) unwrap_all_memberships(task_hash) task_hash['task'] = task.name task_hash end |
#unwrap_all_memberships(task_hash) ⇒ void
This method returns an undefined value.
@param task_hash
83 84 85 86 87 88 89 90 91 |
# File 'lib/checkoff/internal/task_hashes.rb', line 83 def unwrap_all_memberships(task_hash) # @type [Array<Hash>] memberships = task_hash.fetch('memberships', []).dup add_user_task_list(task_hash, memberships) unwrap_memberships(task_hash, memberships, 'section', 'gid') unwrap_memberships(task_hash, memberships, 'section', 'name') unwrap_memberships(task_hash, memberships, 'project', 'gid') unwrap_memberships(task_hash, memberships, 'project', 'name') end |
#unwrap_custom_fields(task_hash) ⇒ void
This method returns an undefined value.
@param task_hash
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/checkoff/internal/task_hashes.rb', line 36 def unwrap_custom_fields(task_hash) # @type [Array<Hash>,nil] custom_fields = task_hash.fetch('custom_fields', nil) return if custom_fields.nil? unwrapped_custom_fields = custom_fields.group_by do |cf| cf['name'] end.transform_values(&:first) task_hash['unwrapped']['custom_fields'] = unwrapped_custom_fields end |
#unwrap_memberships(task_hash, memberships, resource, key) ⇒ Object
@param task_hash
@param resource
@param memberships
@param key
73 74 75 76 77 78 79 |
# File 'lib/checkoff/internal/task_hashes.rb', line 73 def unwrap_memberships(task_hash, memberships, resource, key) # @type [Hash] unwrapped = task_hash.fetch('unwrapped') unwrapped["membership_by_#{resource}_#{key}"] = memberships.group_by do |membership| membership[resource][key] end.transform_values(&:first) end |