Sha256: 66b6abb8c878a499ffd219d829bdf3fc979bcd36569d5d68d884436a224cfef9
Contents?: true
Size: 1.02 KB
Versions: 8
Compression:
Stored size: 1.02 KB
Contents
# encoding: utf-8 # # Another way to reduce the number of cells is to <code>filter</code> the table. # # <code>filter</code> is just like <code>Enumerable#select</code>. Pass it a # block and it will iterate through the cells returning a new # <code>Prawn::Table::Cells</code> instance containing only those cells for # which the block was not false. # require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do data = [ ["Item", "Jan Sales", "Feb Sales"], ["Oven", 17, 89], ["Fridge", 62, 30], ["Microwave", 71, 47] ] table(data) do values = cells.columns(1..-1).rows(1..-1) bad_sales = values.filter do |cell| cell.content.to_i < 40 end bad_sales.background_color = "FFAAAA" good_sales = values.filter do |cell| cell.content.to_i > 70 end good_sales.background_color = "AAFFAA" end end
Version data entries
8 entries across 8 versions & 2 rubygems