Class: Prawn::QRCode::Table::Cell

Inherits:
Table::Cell
  • Object
show all
Defined in:
lib/prawn/qrcode/table/cell.rb

Overview

QRCode is a table cell that renders a QR code inside a table. Most users will create a table via the PDF DSL method make_qr_code_cell.

Constant Summary collapse

QR_OPTIONS =
%I[content qr_code renderer level mode extent pos dot stroke margin align].freeze
CELL_OPTS =
%I[padding borders border_widths border_colors border_lines colspan rowspan at].freeze

Instance Method Summary collapse

Constructor Details

#initialize(pdf, pos, **options) ⇒ Cell

Returns a new instance of Cell.



15
16
17
18
19
20
# File 'lib/prawn/qrcode/table/cell.rb', line 15

def initialize(pdf, pos, **options)
  super(pdf, pos, options.select { |k, _| CELL_OPTS.include?(k) })
  @margin = 4
  @options = options.reject { |k, _| CELL_OPTS.include?(k) }
  @options.each { |k, v| send("#{k}=", v) }
end

Instance Method Details

#draw_contentObject



30
31
32
# File 'lib/prawn/qrcode/table/cell.rb', line 30

def draw_content
  renderer.render(@pdf)
end

#natural_content_heightObject



26
27
28
# File 'lib/prawn/qrcode/table/cell.rb', line 26

def natural_content_height
  renderer.extent
end

#natural_content_widthObject



22
23
24
# File 'lib/prawn/qrcode/table/cell.rb', line 22

def natural_content_width
  renderer.extent
end

#qr_codeObject



38
39
40
41
# File 'lib/prawn/qrcode/table/cell.rb', line 38

def qr_code
  @qr_code = Prawn::QRCode.min_qrcode(content, **@options) unless defined?(@qr_code)
  @qr_code
end

#rendererObject



34
35
36
# File 'lib/prawn/qrcode/table/cell.rb', line 34

def renderer
  @renderer ||= Prawn::QRCode::Renderer.new(qr_code, **@options)
end