class PdfTempura::Document::Table
Attributes
cell_padding[RW]
columns[RW]
name[RW]
padding[RW]
row_count[RW]
row_height[RW]
Public Class Methods
new(name,coordinates,options = {},&block)
click to toggle source
Calls superclass method
PdfTempura::Document::Field::Base::new
# File lib/pdf_tempura/document/table.rb, line 11 def initialize(name,coordinates,options = {},&block) super name, coordinates, [0,0], options @columns = [] instance_eval(&block) if block_given? end
Public Instance Methods
boxed_character_column(name, options = {}, &block)
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 39 def boxed_character_column(name, options = {}, &block) columns << Document::Table::BoxedCharacterColumn.new(name, row_height, @options.merge(options), &block) end
checkbox_column(name, width, options = {})
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 35 def checkbox_column(name, width, options = {}) columns << Document::Table::CheckboxColumn.new(name, width, row_height, @options.merge(options)) end
fields_for(values, &block)
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 47 def fields_for(values, &block) values.inject(self.y) do |y, value_hash| generate_columns(y, value_hash, &block) y - row_height end end
height()
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 23 def height @height ||= row_height * row_count end
space(width)
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 43 def space(width) columns << Document::Table::Spacer.new(width, row_height) end
text_column(name, width, options = {})
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 31 def text_column(name, width, options = {}) columns << Document::Table::TextColumn.new(name, width, row_height, @options.merge(options)) end
width()
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 19 def width table_width + padding_width end
Private Instance Methods
generate_columns(y, values) { |field_at([x,y]), values| ... }
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 56 def generate_columns(y, values) columns.inject(self.x) do |x, column| yield column.field_at([x,y]), values[column.name] if column.generates_field? x + column.width + cell_padding end end
load_options(options)
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 77 def load_options(options) @height = options["height"] @row_height = options["row_height"] @row_count = options["number_of_rows"] @padding = options["padding"] || [0,0,0,0] @cell_padding = options["cell_padding"] || 0 @options = options validate_height end
padding_width()
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 67 def padding_width (columns.any?) ? cell_padding * (columns.count - 1) : 0 end
table_width()
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 63 def table_width columns.map(&:width).inject(0, :+) end
validate_height()
click to toggle source
# File lib/pdf_tempura/document/table.rb, line 71 def validate_height unless row_count && (@row_height || @height) raise ArgumentError.new("You must pass number_of_rows and either height or row_height") end end