Class: BrDanfe::QrCode

Inherits:
Object
  • Object
show all
Defined in:
lib/br_danfe/qr_code.rb

Instance Method Summary collapse

Constructor Details

#initialize(pdf:, qr_code_tag:, box_size:) ⇒ QrCode

Returns a new instance of QrCode.



7
8
9
10
11
# File 'lib/br_danfe/qr_code.rb', line 7

def initialize(pdf:, qr_code_tag:, box_size:)
  @pdf = pdf
  @qr_code_tag = qr_code_tag
  @box_size = box_size
end

Instance Method Details

#renderObject



13
14
15
16
17
18
19
# File 'lib/br_danfe/qr_code.rb', line 13

def render
  qrcode = RQRCode::QRCode.new(@qr_code_tag)
  image = Tempfile.new(%w[qrcode png], binmode: true)
  image.write(qrcode.as_png(module_px_size: 12).to_s)

  @pdf.image(image, width: @box_size, height: @box_size, position: :center)
end