class RQRCode::QRAlphanumeric
Attributes
mode[R]
Public Class Methods
new( data )
click to toggle source
# File lib/rqrcode/qrcode/qr_alphanumeric.rb, line 8 def initialize( data ) @mode = QRMODE[:mode_alpha_numk] raise QRCodeArgumentError, "Not a alpha numeric uppercase string `#{data}`" unless QRAlphanumeric.valid_data?(data) @data = data; end
valid_data?(data)
click to toggle source
# File lib/rqrcode/qrcode/qr_alphanumeric.rb, line 21 def self.valid_data? data data.each_char do |s| return false if ALPHANUMERIC.index(s).nil? end true end
Public Instance Methods
get_length()
click to toggle source
# File lib/rqrcode/qrcode/qr_alphanumeric.rb, line 17 def get_length @data.size end
write( buffer)
click to toggle source
# File lib/rqrcode/qrcode/qr_alphanumeric.rb, line 29 def write( buffer) buffer.alphanumeric_encoding_start(get_length) (@data.size).times do |i| if i % 2 == 0 if i == (@data.size - 1) value = ALPHANUMERIC.index(@data[i]) buffer.put( value, 6 ) else value = (ALPHANUMERIC.index(@data[i]) * 45) + ALPHANUMERIC.index(@data[i+1]) buffer.put( value, 11 ) end end end end