ads_common/lib/ads_common/results_extractor.rb
def normalize_hash_field(field, field_def)
      process_attributes(field, true)
      field_type = field_def[:type]
      field_def = get_full_type_signature(field_type)

      # First checking for xsi:type provided.
      xsi_type_override = determine_xsi_type_override(field, field_def)
      unless xsi_type_override.nil?
        field_def = get_full_type_signature(xsi_type_override)
        return (field_def.nil?) ? field :
            normalize_fields(field, field_def[:fields])
      end

      result = field

      # Now checking for choice options from wsdl.
      choice_type_override = determine_choice_type_override(field, field_def)
      unless choice_type_override.nil?
        # For overrides we need to process sub-field and than return it
        # in the original structure.
        field_key = field.keys.first
        field_data = field[field_key]
        field_def = get_full_type_signature(choice_type_override)
        if !field_def.nil? and field_data.kind_of?(Hash)
          field_data = normalize_fields(field_data, field_def[:fields])
        end
        result = {field_key => field_data}
      else
        # Otherwise using the best we have.
        unless field_def.nil?
          result = normalize_fields(field, field_def[:fields])
        end
      end

      # Convert a single key-value hash to a proper hash if detected.
      if check_key_value_struct(result)
        result = convert_key_value_to_hash(result)
      end

      return result
    end
def normalize_hash_field(field, field_def)
      process_attributes(field, true)
      field_type = field_def[:type]
      field_def = get_full_type_signature(field_type)

      # First checking for xsi:type provided.
      xsi_type_override = determine_xsi_type_override(field, field_def)
      unless xsi_type_override.nil?
        field_def = get_full_type_signature(xsi_type_override)
        return (field_def.nil?) ? field :
            normalize_fields(field, field_def[:fields])
      end

      result = field

      # Now checking for choice options from wsdl.
      choice_type_override = determine_choice_type_override(field, field_def)
      unless choice_type_override.nil?
        # For overrides we need to process sub-field and than return it
        # in the original structure.
        field_key = field.keys.first
        field_data = field[field_key]
        field_def = get_full_type_signature(choice_type_override)
        if !field_def.nil? and field_data.kind_of?(Hash)
          field_data = normalize_fields(field_data, field_def[:fields])
        end
        result = {field_key => field_data}
      else
        # Otherwise using the best we have.
        unless field_def.nil?
          result = normalize_fields(field, field_def[:fields])
        end
      end

      # Convert a single key-value hash to a proper hash if detected.
      if check_key_value_struct(result)
        result = convert_key_value_to_hash(result)
      end

      return result
    end
Normalizes every item of a Hash.