Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 332
polarcare Avatar asked Feb 11 '23 17:02

polarcare


1 Answers

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 
like image 104
Sharvy Ahmed Avatar answered Feb 22 '23 23:02

Sharvy Ahmed