Module: Bloomy::Utilities::Transform

Included in:
Goal, Headline, Issue, Meeting, Scorecard, Todo, Bloomy::User
Defined in:
lib/bloomy/utils/transform.rb

Overview

Provides consistent response transformation across all operations. Handles date parsing and wraps hashes with indifferent access.

Constant Summary collapse

DATE_FIELDS =

Fields that should be parsed as DateTime objects

%i[
  due_date created_at completed_at closed_at updated_at week_start week_end
].freeze

Instance Method Summary collapse

Instance Method Details

#transform_array(array) ⇒ Array<HashWithIndifferentAccess>

Transforms an array of hashes

Examples:

transform_array([{ id: 1 }, { id: 2 }])
#=> [{ "id" => 1 }, { "id" => 2 }]

Parameters:

  • array (Array<Hash>)

    the array of hashes to transform

Returns:

  • (Array<HashWithIndifferentAccess>)

    the transformed array



37
38
39
40
41
# File 'lib/bloomy/utils/transform.rb', line 37

def transform_array(array)
  return [] if array.nil?

  array.map { |item| transform_response(item) }
end

#transform_response(hash) ⇒ HashWithIndifferentAccess?

Transforms a hash response with date parsing and indifferent access

Examples:

transform_response({ created_at: "2024-06-10" })
#=> { "created_at" => #<DateTime: 2024-06-10...> }

Parameters:

  • hash (Hash, nil)

    the hash to transform

Returns:

  • (HashWithIndifferentAccess, nil)

    the transformed hash or nil



23
24
25
26
27
28
# File 'lib/bloomy/utils/transform.rb', line 23

def transform_response(hash)
  return nil if hash.nil?

  result = parse_dates(hash)
  HashWithIndifferentAccess.new(result)
end