Class: AtPay::Button::QRCode

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(button) ⇒ QRCode

Returns a new instance of QRCode.



11
12
13
14
# File 'lib/atpay/button/qr_code.rb', line 11

def initialize(button)
  content = CGI.unescape(button.default_mailto)
  @qr     = QREncoder.encode(content, correction: :low)
end

Instance Attribute Details

#qrObject (readonly)

Returns the value of attribute qr.



9
10
11
# File 'lib/atpay/button/qr_code.rb', line 9

def qr
  @qr
end

Instance Method Details

#png(pixels_per_module = 6) ⇒ Object



16
17
18
# File 'lib/atpay/button/qr_code.rb', line 16

def png(pixels_per_module=6)
  @qr.png(pixels_per_module: pixels_per_module).to_blob
end

#svgObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/atpay/button/qr_code.rb', line 20

def svg
  points = @qr.points
  scale  = 10

  Rasem::SVGImage.new(@qr.width * scale, @qr.height * scale) do
    points.each do |point|
      rectangle point[0] * scale, point[1] * scale, scale, scale
    end
  end.output
end