Class: Payday::QrCode
- Inherits:
-
Object
- Object
- Payday::QrCode
- Defined in:
- lib/payday/qr_code.rb
Overview
Draws a QR code as an SVG.
The matrix comes straight from RQRCode, so the payload and its error correction level are untouched and the code carries exactly the same data it always did. Only the drawing changes: vector instead of a 200px raster, lightly rounded modules, and the three finder patterns drawn as rounded frames.
Rounding is kept deliberately slight. These codes are scanned off paper, sometimes off a bad photocopy, and on a Verifactu invoice a code that will not scan is a compliance problem rather than a cosmetic one. Modules keep their full square footprint apart from a softened corner, so a scanner sees the same geometry the old raster produced.
Constant Summary collapse
- QUIET_ZONE =
modules of clear space; the QR spec's minimum
4- UNIT =
user units per module
10- RADIUS =
corner radius of a data module, out of UNIT
1.5- FINDER =
finder patterns are 7 modules square
7- EYE_RADIUS =
Corner radius of a finder frame. Above roughly 1.2 modules the curve starts cutting the corner module out of the ring, which changes what a scanner reads.
10- DARK =
'#111111'- LIGHT =
'#ffffff'
Instance Method Summary collapse
-
#initialize(data) ⇒ QrCode
constructor
A new instance of QrCode.
- #to_svg ⇒ Object
Constructor Details
#initialize(data) ⇒ QrCode
Returns a new instance of QrCode.
30 31 32 |
# File 'lib/payday/qr_code.rb', line 30 def initialize(data) @modules = RQRCode::QRCode.new(data.to_s).modules end |
Instance Method Details
#to_svg ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/payday/qr_code.rb', line 34 def to_svg <<~SVG <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 #{side} #{side}" shape-rendering="geometricPrecision"> <rect width="#{side}" height="#{side}" fill="#{LIGHT}"/> #{(data_modules + finders).join("\n")} </svg> SVG end |