Class Barby::QrCode
In: lib/barby/barcode/qr_code.rb
Parent: Barcode2D
EAN13 Bookland EAN8 Barcode1D Code128 Code25 Code93 Code39 Barcode Barcode2D QrCode Pdf417 Code128A Code128B Code128C GS1128 Outputter CairoOutputter PngOutputter ASCIIOutputter RmagickOutputter PDFWriterOutputter SvgOutputter PrawnOutputter Code25IATA Code25Interleaved lib/barby/barcode/gs1_128.rb lib/barby/outputter/png_outputter.rb lib/barby/outputter/svg_outputter.rb lib/barby/outputter/rmagick_outputter.rb lib/barby/barcode.rb lib/barby/outputter/ascii_outputter.rb lib/barby/outputter.rb lib/barby/barcode/code_128.rb lib/barby/barcode/code_39.rb lib/barby/outputter/pdfwriter_outputter.rb lib/barby/barcode/code_93.rb lib/barby/outputter/prawn_outputter.rb lib/barby/barcode/ean_8.rb lib/barby/barcode/pdf_417.rb lib/barby/barcode/code_25_iata.rb lib/barby/outputter/cairo_outputter.rb lib/barby/barcode/ean_13.rb lib/barby/barcode/code_25.rb lib/barby/barcode/code_25_interleaved.rb lib/barby/barcode/qr_code.rb lib/barby/barcode/bookland.rb VERSION Barby dot/m_23_0.png

QrCode is a thin wrapper around the RQRCode library

Methods

data=   encoding   level   new   rqrcode   size   to_s  

Constants

SIZES = { #L M Q H 1 => [17, 14, 11, 7], 2 => [32, 26, 20, 14], 3 => [53, 42, 32, 24], 4 => [78, 62, 46, 34], 5 => [106, 84, 60, 44], 6 => [134, 106, 74, 58], 7 => [154, 122, 86, 64], 8 => [192, 152, 108, 84], 9 => [230, 180, 130, 98], 10 => [271, 213, 151, 119], 11 => [321, 251, 177, 137], 12 => [367, 287, 203, 155], 13 => [425, 331, 241, 177], 14 => [458, 362, 258, 194], 15 => [520, 412, 292, 220], 16 => [586, 450, 322, 250], 17 => [644, 504, 364, 280], 18 => [718, 560, 394, 310], 19 => [792, 624, 442, 338], 20 => [858, 666, 482, 382], 21 => [929, 711, 509, 403], 22 => [1003, 779, 565, 439], 23 => [1091, 857, 611, 461], 24 => [1171, 911, 661, 511], 25 => [1273, 997, 715, 535], 26 => [1367, 1059, 751, 593], 27 => [1465, 1125, 805, 625], 28 => [1528, 1190, 868, 658], 29 => [1628, 1264, 908, 698], 30 => [1732, 1370, 982, 742], 31 => [1840, 1452, 1030, 790], 32 => [1952, 1538, 1112, 842], 33 => [2068, 1628, 1168, 898], 34 => [2188, 1722, 1228, 958], 35 => [2303, 1809, 1283, 983], 36 => [2431, 1911, 1351, 1051], 37 => [2563, 1989, 1423, 1093], 38 => [2699, 2099, 1499, 1139], 39 => [2809, 2213, 1579, 1219], 40 => [2953, 2331, 1663, 1273]   Maximum sizes for each correction level for binary data It‘s an array
LEVELS = { :l => 0, :m => 1, :q => 2, :h => 3 }

Attributes

data  [R] 
level  [W] 
size  [W] 

Public Class methods

[Source]

    # File lib/barby/barcode/qr_code.rb, line 42
42:     def initialize(data, options={})
43:       self.data = data
44:       options.each{|k,v| send("#{k}=", v) }
45:       raise(ArgumentError, "data too large") unless size
46:     end

Public Instance methods

[Source]

    # File lib/barby/barcode/qr_code.rb, line 49
49:     def data=(data)
50:       @data = data
51:     end

[Source]

    # File lib/barby/barcode/qr_code.rb, line 54
54:     def encoding
55:       rqrcode.modules.map{|r| r.inject(''){|s,m| s << (m ? '1' : '0') } }
56:     end

Error correction level Can be one of [:l, :m, :q, :h] (7%, 15%, 25%, 30%)

[Source]

    # File lib/barby/barcode/qr_code.rb, line 61
61:     def level
62:       @level || :l
63:     end

[Source]

    # File lib/barby/barcode/qr_code.rb, line 66
66:     def size
67:       #@size is only used for manual override, if it's not set
68:       #manually the size is always dynamic, calculated from the
69:       #length of the data
70:       return @size if @size
71: 
72:       level_index = LEVELS[level]
73:       length = data.length
74:       found_size = nil
75:       SIZES.each do |size,max_values|
76:         if max_values[level_index] >= length
77:           found_size = size
78:           break
79:         end
80:       end
81:       found_size
82:     end

[Source]

    # File lib/barby/barcode/qr_code.rb, line 85
85:     def to_s
86:       data[0,20]
87:     end

Private Instance methods

Generate an RQRCode object with the available values

[Source]

    # File lib/barby/barcode/qr_code.rb, line 93
93:     def rqrcode
94:       RQRCode::QRCode.new(data, :level => level, :size => size)
95:     end

[Validate]