Search code examples
rubyarraysprawn

Create array for Prawn table if value exists


I am using the Prawn gem to generate a table within a PDF file. The code looks like this:

count = 0
table([
  ["UnitID", "First Name", "Last Name", "NPS Score", "Comments"],
  [
    unitid_array[count],
    firstname_array[count],
    lastname_array[count],
    nps_score_array[count],
    comment_array[count]
  ]
])

This produces a table using the first element of each array I am passing to it. I need to add second array that passes the second element, and so on until the arrays are out of objects. How is this possible?


Solution

  • table([
      ["UnitID", "First Name", "Last Name", "NPS Score", "Comments"],
      *[unitid_array, firstname_array, lastname_array, nps_score_array, comment_array]
      .transpose
    ])