Sha256: 129f9ecf3801ecbb7db94dfbdaf55f832de5b16b489b99bad2932db4970ad387

Contents?: true

Size: 721 Bytes

Versions: 7

Compression:

Stored size: 721 Bytes

Contents

# Note: You'll need qrencoder (https://rubygems.org/gems/qrencoder)
# and rasem (https://rubygems.org/gems/rasem) for this functionality.

require 'qrencoder'
require 'rasem'
require 'cgi'

class AtPay::Button::QRCode
  attr_reader :qr

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

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

  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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
atpay_ruby-0.0.17 lib/atpay/button/qr_code.rb
atpay_ruby-0.0.16 lib/atpay/button/qr_code.rb
atpay_ruby-0.0.15 lib/atpay/button/qr_code.rb
atpay_ruby-0.0.13 lib/atpay/button/qr_code.rb
atpay_ruby-0.0.12 lib/atpay/button/qr_code.rb
atpay_ruby-0.0.11 lib/atpay/button/qr_code.rb
atpay_ruby-0.0.10 lib/atpay/button/qr_code.rb