def to_csv data
      attributes = data.first&.keys || []

      CSV.generate(headers: true) do |csv|
        csv << attributes

        data.each do |row|
          csv << attributes.map do |att|
            row[att]
          end
        end
      end
    end
def to_csv data
      attributes = data.first&.keys || []

      CSV.generate(headers: true) do |csv|
        csv << attributes

        data.each do |row|
          csv << attributes.map do |att|
            row[att]
          end
        end
      end
    end
Array of hash data to csv format