qr_code_maker

A simple, zero-dependency, standard-library-only QR code generator for Ruby.

qr_code_maker is written in pure Ruby, with no external gem dependencies. It supports the full QR Code specification (Versions 1-40, ECC levels L, M, Q, H) and generates vector SVG strings or terminal ASCII art.

Installation

Add this line to your application's Gemfile:

gem 'qr_code_maker'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install qr_code_maker

Usage

High-Level API (Quickest)

You can generate QR code SVG strings or ASCII prints directly from a URL or text string:

require 'qr_code_maker'

# Generate a raw SVG string
svg = QrCodeMaker.generate_svg("https://github.com")

# Generate an ASCII terminal representation
ascii = QrCodeMaker.generate_ascii("https://github.com")
puts ascii

Object-Oriented API

If you need more control, you can instantiate a QRCode object:

require 'qr_code_maker'

# Create the QR Code object with custom Error Correction Level (:l, :m, :q, or :h)
qr = QrCodeMaker::QRCode.new("https://github.com", level: :m)

# Access metadata
puts qr.version            # The auto-chosen QR version (1-40)
puts qr.module_count       # Dimension of the grid (width/height)
puts qr.checked?(0, 0)     # Check if the module at (row, col) is dark (true) or light (false)

# Render to SVG with options
svg = qr.as_svg(
  color: "black",          # Foreground color of the modules
  bg_color: "white",       # Background color (set to nil or false for transparent)
  module_size: 10,         # Size of each module in pixels
  margin: 4                # Number of modules for quiet zone margin
)

Running Tests

Run the automated test suite with:

ruby -Ilib -Itest test/test_qr_code_maker.rb

License

The gem is available as open source under the terms of the MIT License.