features/steps/response_steps.rb
# Walk array/hash to determine maximum depth. A scalar (anything but an
# Array or Hash) has depth 0.
Walk array/hash to determine maximum depth. A scalar (anything but an
Array or Hash) has depth 0.
Walk array / hash to determine maximum depth . A scalar ( anything but an Array or Hash ) has depth 0 .
def count_structure_levels(obj)
  if obj.respond_to?(:keys)
    max_depth = 0
    obj.keys.each do |key|
      child_levels = 1 + count_structure_levels(obj[key])
      max_depth = [max_depth, child_levels].max
    end
    max_depth
  elsif obj.is_a?(Array)
    max_depth = 0
    obj.each do |child|
      child_levels = 1 + count_structure_levels(child)
      max_depth = [max_depth, child_levels].max
    end
    max_depth
  else
    0
  end
end
def count_structure_levels ( obj ) if obj . respond_to? ( :keys ) max_depth = 0 obj . keys . each do | key | child_levels = 1 + count_structure_levels ( obj [ key ] ) max_depth = [ max_depth , child_levels ] . max end max_depth elsif obj . is_a? ( Array ) max_depth = 0 obj . each do | child | child_levels = 1 + count_structure_levels ( child ) max_depth = [ max_depth , child_levels ] . max end max_depth else 0 end end
Walk array/hash to determine maximum depth.
Walk array / hash to determine maximum depth .
# empty hash also has depth 0. # empty array also has depth 0.
obj
<not_specific>