Method: Prawn::QRCode::Renderer#initialize

Defined in:
lib/prawn/qrcode.rb

#initialize(qr_code, **options) ⇒ Renderer

creates a new renderer for the given QR code

Options :dot and :extent are mutually exclusive.

Parameters:

  • qr_code (RQRCode::QRCode)

    QR code to render

  • options (Hash)

    additional options

Options Hash (**options):

  • :dot (Float)

    size of a dot in pt (1/72 in)

  • :pos (Array)

    Two-element array containing the position at which the QR-Code should be rendered. Defaults to [0,cursor]

  • :stroke (bool)

    whether to draw bounds around the QR Code. Defaults to true.

  • :foreground_color (string)

    6-digit hex string specifying foreground color; default: ‘000000’

  • :background_color (string)

    6-digit hex string specifying background color; default: ‘FFFFFF’

  • :stroke_color (string)

    6-digit hex string specifying stroke color; default: ‘000000’

  • :margin (integer)

    number of modules as margin around QRcode (default: 4)

  • :extent (float)

    overall width/height of QR code in pt (1/72 in)

  • :debug (bool)

    render a coordinate grid around the QRCode if true (uses Prawn#stroke_axis)

  • :align (symbol)

    alignment within the current bounding box. Valid values are :left, :right, and :center. If set this option overrides the horizontal positioning specified in :pos. Defaults to nil.

Raises:

  • (QRCodeError)

    if both extent and dot are specified.

Since:

  • 0.5.0



124
125
126
127
128
129
130
# File 'lib/prawn/qrcode.rb', line 124

def initialize(qr_code, **options)
  raise QRCodeError, 'Specify either :dot or :extent, not both' if options.key?(:dot) && options.key?(:extent)

  @stroke = true
  @qr_code = qr_code
  options.select { |k, _v| RENDER_OPTS.include?(k) }.each { |k, v| send("#{k}=", v) }
end