$ show whomwah/rqrcode
RQRCode is a Ruby gem that generates QR codes from strings and renders them into multiple output formats: SVG, PNG, HTML, and ANSI terminal output. It wraps the `rqrcode_core` gem for QR matrix generation and adds rendering capabilities. The SVG renderer includes an optimized path-tracing algorithm that produces compact output by tracing the perimeter of dark modules rather than drawing individual rectangles, demonstrating significant engineering craftsmanship. The PNG renderer supports two sizing strategies (Google-inspired and original) and accepts flexible color inputs. The gem includes a comprehensive benchmarking suite (using benchmark-ips, memory_profiler, and stackprof) that measures both end-to-end and rendering-only performance, with results saved as JSON for tracking over time. The codebase is well-structured, follows Ruby conventions, and has thorough test coverage across all export formats.
The LLM identified 2 files worth highlighting for reuse:
The SVG export module contains two internal rendering classes: `Rect` (simple per-module rectangles) and `Path` (optimized perimeter tracing). The `Path` class implements an edge-detection algorithm that identifies horizontal and vertical edges between dark and light modules, traces continuous paths, and outputs compact SVG path commands. This reduces SVG size by 70-90% compared to rect-based rendering. The algorithm is self-contained (operates on @qrcode.modules) and could be extracted as a general binary matrix to SVG path converter for any grid-based visualization.
A reusable benchmarking framework that provides clean methods for running IPS, memory, and stack profiling benchmarks. It includes automatic result saving to JSON files with timestamps, support for both end-to-end and rendering-only benchmarks, and shared test data. The helper is designed to be format-agnostic and could be extracted into a standalone gem for benchmarking any Ruby codebase. It demonstrates good practices in performance measurement: separating generation from rendering costs, tracking multiple metrics, and persisting results for trend analysis.