Sha256: c54a4f02447851487e7ceb0ba6586b1f9fc7610cd0767c367d4b51c39be17130

Contents?: true

Size: 1.07 KB

Versions: 77

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Checkoff
  module Internal
    # Builds on the standard API representation of an Asana project with some
    # convenience keys.
    class ProjectHashes
      # @param _deps [Hash]
      def initialize(_deps = {}); end

      # @param project_obj [Asana::Resources::Project]
      # @param project [String, Symbol<:not_specified, :my_tasks>]
      #
      # @return [Hash]
      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

      private

      # @param project_hash [Hash]
      # @return [void]
      def unwrap_custom_fields(project_hash)
        unwrapped_custom_fields = project_hash.fetch('custom_fields', []).group_by do |cf|
          cf['name']
        end.transform_values(&:first)
        project_hash['unwrapped']['custom_fields'] = unwrapped_custom_fields
      end
    end
  end
end

Version data entries

77 entries across 77 versions & 1 rubygems

Version Path
checkoff-0.196.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.195.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.194.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.193.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.192.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.191.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.190.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.189.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.188.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.187.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.186.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.185.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.184.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.183.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.182.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.181.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.180.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.179.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.178.0 lib/checkoff/internal/project_hashes.rb
checkoff-0.177.0 lib/checkoff/internal/project_hashes.rb