lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb
def transform_array(array)
        transformed_to_hash = Hash.new

        array.each_with_index do |ele, i|
          # Set the key to the value of the respresentative key
          key = ele['key'] if ele['key']
          key = ele['name'] if ele['name']

          # Merge this new key into the hash
          transformed_to_hash.merge!({ key => Hash.new })

          # Then add the corresponding key/values to this new hash
          ele.each_pair do |k, v|
            if k != 'key' && k != 'name'
              transformed_to_hash[key].merge!(transform_pair(k, v))
            end
          end
        end

        transformed_to_hash
      end
##
# Returns an hash from a collapsed array, using the values of 'key' or 'name' as the collpassed hash key
#
# @param [Array] the array of values to collapse into a Hash
# @return [Hash] the collapsed Hash
Returns an hash from a collapsed array, using the values of 'key' or 'name' as the collpassed hash key
Returns an hash from a collapsed array using the values of ' key ' or ' name ' as the collpassed hash key
def transform_array(array)
        transformed_to_hash = Hash.new
        array.each_with_index do |ele, i|
          key = ele['key'] if ele['key']
          key = ele['name'] if ele['name']
          transformed_to_hash.merge!({ key => Hash.new })
          ele.each_pair do |k, v|
            if k != 'key' && k != 'name'
              transformed_to_hash[key].merge!(transform_pair(k, v))
            end
          end
        end
        transformed_to_hash
      end
def transform_array ( array ) transformed_to_hash = Hash . new array . each_with_index do | ele , i | key = ele [ 'key' ] if ele [ 'key' ] key = ele [ 'name' ] if ele [ 'name' ] transformed_to_hash . merge! ( { key => Hash . new } ) ele . each_pair do | k , v | if k != 'key' && k != 'name' transformed_to_hash [ key ] . merge! ( transform_pair ( k , v ) ) end end end transformed_to_hash end
Returns an hash from a collapsed array, using the values of 'key' or 'name' as the collpassed hash key
Returns an hash from a collapsed array using the values of ' key ' or ' name ' as the collpassed hash key
# Set the key to the value of the respresentative key # Merge this new key into the hash # Then add the corresponding key/values to this new hash
the collapsed Hash
the collapsed Hash
Hash
array
the array of values to collapse into a Hash
the array of values to collapse into a Hash