资源说明:A Ruby library that encodes QR Codes
		
		
		
		
		
		
		# RQRCode

[](https://github.com/testdouble/standard)
[RQRCode](https://github.com/whomwah/rqrcode) is a library for creating and rendering QR codes into various formats. It has a simple interface with all the standard QR code options. It was adapted from the Javascript library by Kazuhiko Arase.
* QR code is trademarked by Denso Wave inc
* Minimum Ruby version is `>= 2.3`
* For `rqrcode` releases `< 2.0.0` please use [this README](https://github.com/whomwah/rqrcode/blob/v1.2.0/README.md)
* For `rqrcode` releases `< 1.0.0` please use [this README](https://github.com/whomwah/rqrcode/blob/v0.9.0/README.md)
## Installing
Add this line to your application's `Gemfile`:
```ruby
gem "rqrcode", "~> 2.0"
```
or install manually:
```ruby
gem install rqrcode
```
## Basic usage example
```ruby
require "rqrcode"
qr = RQRCode::QRCode.new("https://kyan.com")
puts qr.to_s
# to_s( dark: "x", light: " " ) # defaults
xxxxxxx xxxxxxx  xxx  xxxxxxx
x     x  x  xxx   xx  x     x
x xxx x xx x x     xx x xxx x
x xxx x      xx xx xx x xxx x
x xxx x x x       xxx x xxx x
x     x  xxx x xx x x x     x
...
```
Easy, but unlikely to be readable. For this you will need to use one of the many [rendering options](#render-types) below.
### Advanced Options
These are the various QR code generation options provided by the underlying [rqrcode_core](https://github.com/whomwah/rqrcode_core). You may actually only need this library if you don't need the various rendering options `rqrcode` provides, but just need the data structure.
```
Expects a string or array (for multi-segment encoding) to be parsed in, other args are optional
  data - the string, QRSegment or array of Hashes (with data:, mode: keys) you wish to encode
  size - the size (Integer) of the QR Code (defaults to smallest size needed to encode the data)
  max_size - the max_size (Integer) of the QR Code (default RQRCodeCore::QRUtil.max_size)
  level - the error correction level, can be:
    * Level :l 7%  of code can be restored
    * Level :m 15% of code can be restored
    * Level :q 25% of code can be restored
    * Level :h 30% of code can be restored (default :h)
  mode - the mode of the QR Code (defaults to :alphanumeric or :byte_8bit, depending on the input data,
         only used when data is a string):
    * :number
    * :alphanumeric
    * :byte_8bit
    * :kanji
```
Example
```ruby
simple_qrcode = RQRCodeCore::QRCode.new("https://kyan.com", size: 1, level: :m, mode: :alphanumeric)
segment_qrcode = QRCodeCore::QRCode.new({ data: "foo", mode: :byte_8bit })
multi_qrcode = RQRCodeCore::QRCode.new([
  { data: 'foo', mode: :byte_8bit },
  { data: 'bar1', mode: :alphanumeric }
])
```
## Render types
You probably want to output your QR code in a specific format. We make this easy by providing a bunch of formats to choose from below, each with their own set of options:
### `as_svg`
The SVG renderer will produce a stand-alone SVG as a `String`
```
Options:
offset          - Padding around the QR Code in pixels
                  (default 0)
fill            - Background color e.g "ffffff" or :white or :currentColor
                  (default none)
color           - Foreground color e.g "000" or :black or :currentColor
                  (default "000")
module_size     - The Pixel size of each module
                  (defaults 11)
shape_rendering - SVG Attribute: auto | optimizeSpeed | crispEdges | geometricPrecision
                  (defaults crispEdges)
standalone      - Whether to make this a full SVG file, or only an svg to embed in other svg
                  (default true)
use_path        - Use  to render SVG rather than  to significantly reduce size
                  and quality. This will become the default in future versions.
                  (default false)
viewbox         - Replace the `svg.width` and `svg.height` attribute with `svg.viewBox` to
                  allow CSS scaling
                  (default false)
svg_attributes  - A optional hash of custom     
					
									本源码包内暂不包含可直接显示的源代码文件,请下载源码包。
							
		 English
 English

