Class: PdfTempura::Document::Table

Inherits:
Field::Base show all
Defined in:
lib/pdf_tempura/document/table.rb

Defined Under Namespace

Classes: BoxedCharacterColumn, CheckboxColumn, Column, Spacer, TextColumn

Instance Attribute Summary collapse

Attributes inherited from Field::Base

#coordinates, #dimensions

Instance Method Summary collapse

Methods inherited from Field::Base

#x, #y

Methods included from Validation

included

Constructor Details

#initialize(name, coordinates, options = {}, &block) ⇒ Table

Returns a new instance of Table.



11
12
13
14
15
16
17
# 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

Instance Attribute Details

#cell_paddingObject

Returns the value of attribute cell_padding.



4
5
6
# File 'lib/pdf_tempura/document/table.rb', line 4

def cell_padding
  @cell_padding
end

#columnsObject

Returns the value of attribute columns.



4
5
6
# File 'lib/pdf_tempura/document/table.rb', line 4

def columns
  @columns
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/pdf_tempura/document/table.rb', line 4

def name
  @name
end

#paddingObject

Returns the value of attribute padding.



4
5
6
# File 'lib/pdf_tempura/document/table.rb', line 4

def padding
  @padding
end

#row_countObject

Returns the value of attribute row_count.



4
5
6
# File 'lib/pdf_tempura/document/table.rb', line 4

def row_count
  @row_count
end

#row_heightObject

Returns the value of attribute row_height.



4
5
6
# File 'lib/pdf_tempura/document/table.rb', line 4

def row_height
  @row_height
end

Instance Method Details

#boxed_character_column(name, options = {}, &block) ⇒ Object



39
40
41
# 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 = {}) ⇒ Object



35
36
37
# 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) ⇒ Object



47
48
49
50
51
52
# 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

#heightObject



23
24
25
# File 'lib/pdf_tempura/document/table.rb', line 23

def height
  @height ||= row_height * row_count
end

#space(width) ⇒ Object



43
44
45
# 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 = {}) ⇒ Object



31
32
33
# 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

#widthObject



19
20
21
# File 'lib/pdf_tempura/document/table.rb', line 19

def width
  table_width + padding_width
end