Module: QREncoder

Defined in:
lib/qrencoder.rb,
lib/qrencoder/png.rb,
lib/qrencoder/qrcode.rb,
lib/qrencoder/version.rb,
ext/qrencoder_ext/qrencoder_ext.c

Defined Under Namespace

Classes: PNG, QRCode

Constant Summary collapse

QR_MODE_NUM =

Numeric-only encoding mode

0
QR_MODE_AN =

Alphanumeric-only encoding mode

1
QR_MODE_8 =

8-bit ASCII encoding mode

2
QR_MODE_KANJI =

Kanji encoding mode

3
QR_ECLEVEL_L =

Low error correction

0
QR_ECLEVEL_M =

Medium error correction

1
QR_ECLEVEL_Q =

Medium-high error correction

2
QR_ECLEVEL_H =

High error correction

3
VERSION =
'1.4.1'

Class Method Summary collapse

Class Method Details

.correctionsObject



52
53
54
55
56
57
58
59
# File 'lib/qrencoder.rb', line 52

def self.corrections
  {
    :low => QR_ECLEVEL_L,
    :medium => QR_ECLEVEL_M,
    :quarter => QR_ECLEVEL_Q,
    :high => QR_ECLEVEL_H
  }
end

.encode(string, options = {}) ⇒ Object

Encode a string, return a QRCode object

This method takes 2 arguments: the string you wish to encode, and a hash of options. The options are as follows:

:version

An integer representing the minimum QRCode version (default: 1)

:correction

The amount of error correction to apply. One of :low, :medium, :quarter, :high. (default: :low)

:mode

The encoding mode to use. Must be one of :numeric, :alphanumeric, :ascii, :kanji. (default: :ascii)

:case_sensitive

Set to false if case does not matter. (default: true)

For more information about what each of these modes and correction levels mean, see QRCode.new



43
44
45
46
47
48
49
50
# File 'lib/qrencoder.rb', line 43

def self.encode(string, options={})
  version = options[:version] || 1
  correction = corrections[options[:correction] || :low]
  mode = modes[options[:mode] || :ascii]
  case_sensitive = options[:case_sensitive] == false ? 0 : 1
  string.upcase! if mode == QR_MODE_AN
  QRCode.new(string.to_s, version, correction, mode, case_sensitive)
end

.modesObject



61
62
63
64
65
66
67
68
# File 'lib/qrencoder.rb', line 61

def self.modes
  {
    :numeric => QR_MODE_NUM,
    :alphanumeric => QR_MODE_AN,
    :ascii => QR_MODE_8,
    :kanji => QR_MODE_KANJI
  }
end