def flatten_hash(hash, prefix=nil)
      new_hash ||= {}
      hash.each do |key, val|
        key =  prefix ? :"#{prefix}_#{key}" : key
        case val
        when Hash
          new_hash.update flatten_hash(val, key)
        else
          new_hash[key] = val
        end
      end
      return new_hash
    end
def flatten_hash(hash, prefix=nil)
      new_hash ||= {}
      hash.each do |key, val|
        key =  prefix ? :"#{prefix}_#{key}" : key
        case val
        when Hash
          new_hash.update flatten_hash(val, key)
        else
          new_hash[key] = val
        end
      end
      return new_hash
    end
Converts deeply nested hash into only one level structure