Sha256: a650247dcfed1f1494018f4f31bced4169baefc321146a98ded6537141a954cc

Contents?: true

Size: 1.02 KB

Versions: 11

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::ManualBuilder::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

11 entries across 11 versions & 2 rubygems

Version Path
prawn-table-0.2.2 manual/table/filtering.rb
prawn-table-0.2.1 manual/table/filtering.rb
prawn-table-0.2.0 manual/table/filtering.rb
prawn-table-0.1.2 manual/table/filtering.rb
prawn-table-0.1.1 manual/table/filtering.rb
prawn-table-0.1.0 manual/table/filtering.rb
prawn-table-0.0.4 manual/table/filtering.rb
prawn-table-0.0.3 manual/table/filtering.rb
prawn-table-0.0.2 manual/table/filtering.rb
prawn-table-0.0.1 manual/table/filtering.rb
prawn-1.1.0 manual/table/filtering.rb