Module: Prawn::QRCode
- Defined in:
- lib/prawn/qrcode.rb,
lib/prawn/qrcode/table.rb,
lib/prawn/qrcode/version.rb,
lib/prawn/qrcode/table/cell.rb
Defined Under Namespace
Modules: Table Classes: QRCodeError, Renderer
Constant Summary collapse
- DEFAULT_DOTSIZE =
DEFAULT_DOTSIZE defines the default size for QR Code modules in multiples of 1/72 in
1.to_f
- VERSION =
'0.5.2'.freeze
Class Method Summary collapse
-
.dotsize(qr_code, extent, margin = 4) ⇒ Float
dotsize calculates the required dotsize for a QR code to be rendered with the given extent and the module size.
-
.min_qrcode(content, qr_version = 0, level: :m, mode: nil) ⇒ RQRCode::QRCode
Creates a QRCode with a minimal size to fit the data with the requested error correction level.
Instance Method Summary collapse
-
#print_qr_code(content, level: :m, mode: nil, pos: [0, cursor], **options) ⇒ Object
Prints a QR Code to the PDF document.
-
#render_qr_code(qr_code, **options) ⇒ Object
Renders a prepared QR code (RQRCode::QRCode) int the pdf.
Class Method Details
.dotsize(qr_code, extent, margin = 4) ⇒ Float
dotsize calculates the required dotsize for a QR code to be rendered with the given extent and the module size
61 62 63 |
# File 'lib/prawn/qrcode.rb', line 61 def self.dotsize(qr_code, extent, margin = 4) extent.to_f / (2 * margin + qr_code.modules.length).to_f end |
.min_qrcode(content, qr_version = 0, level: :m, mode: nil) ⇒ RQRCode::QRCode
Creates a QRCode with a minimal size to fit the data with the requested error correction level.
45 46 47 48 49 50 51 |
# File 'lib/prawn/qrcode.rb', line 45 def self.min_qrcode(content, qr_version = 0, level: :m, mode: nil, **) qr_version += 1 RQRCode::QRCode.new(content, size: qr_version, level: level, mode: mode) rescue RQRCodeCore::QRCodeRunTimeError retry if qr_version < 40 raise end |
Instance Method Details
#print_qr_code(content, level: :m, mode: nil, pos: [0, cursor], **options) ⇒ Object
Prints a QR Code to the PDF document. The QR Code creation happens on the fly.
75 76 77 78 |
# File 'lib/prawn/qrcode.rb', line 75 def print_qr_code(content, level: :m, mode: nil, pos: [0, cursor], **) qr_code = Prawn::QRCode.min_qrcode(content, level: level, mode: mode) render_qr_code(qr_code, pos: pos, **) end |