Class: Checkoff::Internal::ProjectHashes

Inherits:
Object
  • Object
show all
Defined in:
lib/checkoff/internal/project_hashes.rb,
sig/checkoff.rbs

Overview

Builds on the standard API representation of an Asana project with some convenience keys.

Instance Method Summary collapse

Constructor Details

#initialize(_deps = {}) ⇒ ProjectHashes

@param _deps

Parameters:

  • _deps (::Hash[untyped, untyped]) (defaults to: {})


10
# File 'lib/checkoff/internal/project_hashes.rb', line 10

def initialize(_deps = {}); end

Instance Method Details

#project_to_h(project_obj, project: :not_specified) ⇒ ::Hash[untyped, untyped]

sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param project_obj

@param project — - :not_specified, :my_tasks

Parameters:

  • project_obj (Asana::Resources::Project)
  • project: (String, Symbol) (defaults to: :not_specified)

Returns:

  • (::Hash[untyped, untyped])


16
17
18
19
20
21
22
# File 'lib/checkoff/internal/project_hashes.rb', line 16

def project_to_h(project_obj, project: :not_specified)
  project = project_obj.name if project == :not_specified
  project_hash = { **project_obj.to_h, 'project' => project }
  project_hash['unwrapped'] = {}
  unwrap_custom_fields(project_hash)
  project_hash
end

#unwrap_custom_fields(project_hash) ⇒ void

This method returns an undefined value.

@param project_hash

Parameters:

  • project_hash (::Hash[untyped, untyped])


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/checkoff/internal/project_hashes.rb', line 28

def unwrap_custom_fields(project_hash)
  # @type [Array<Hash>,nil]
  custom_fields = project_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)
  project_hash['unwrapped']['custom_fields'] = unwrapped_custom_fields
end