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[String, Object]

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

@param project — - a String is a project name

Parameters:

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

Returns:

  • (::Hash[String, Object])


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

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])


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

def unwrap_custom_fields(project_hash)
  # @type [Array<Hash{String => Object}>,nil]
  custom_fields = project_hash['custom_fields']

  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