ruby-on-railsprawnruby-2.1

Ruby prawn-table gem : How to select last row of a table?


I have a prawn table like the following:

table info_rows do
  row(0).font_style = :bold
  row(0).align = :center
  row(0).borders = [:top, :bottom, :left, :right]
  row(1..50).borders = [:left, :right]
  self.header = true
  self.row_colors = ['EEEEEE', 'FFFFFF']
  self.column_widths = col_sizes
end

I need to put a bottom border on the last row, but am not sure how to detect the last row inside the loop? Something like(the following if statement inside loop obviously doesn't work/ just example)...

table info_rows do
  row(0).font_style = :bold
  row(0).align = :center
  row(0).borders = [:top, :bottom, :left, :right]
  row(1..50).borders = [:left, :right]

  if row.last
    ?(?).borders = [:bottom, :left, :right]
  end

  self.header = true
  self.row_colors = ['EEEEEE', 'FFFFFF']
  self.column_widths = col_sizes
end 

Any ideas are most welcomed.

I'm using Ruby - 2.1.2


Solution

  • You can try this:

    table info_rows do
      row(0).font_style = :bold
      row(0).align = :center
      row(0).borders = [:top, :bottom, :left, :right]
      row(1..50).borders = [:left, :right]
      row(-1).borders = [:bottom, :left, :right]
    
      self.header = true
      self.row_colors = ['EEEEEE', 'FFFFFF']
      self.column_widths = col_sizes
    end