Class: RQRCode::QRAlphanumeric
- Inherits:
-
Object
- Object
- RQRCode::QRAlphanumeric
- Defined in:
- lib/rqrcode/qrcode/qr_alphanumeric.rb
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Class Method Summary collapse
Instance Method Summary collapse
- #get_length ⇒ Object
-
#initialize(data) ⇒ QRAlphanumeric
constructor
A new instance of QRAlphanumeric.
- #write(buffer) ⇒ Object
Constructor Details
#initialize(data) ⇒ QRAlphanumeric
Returns a new instance of QRAlphanumeric.
8 9 10 11 12 13 14 |
# 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 |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
6 7 8 |
# File 'lib/rqrcode/qrcode/qr_alphanumeric.rb', line 6 def mode @mode end |
Class Method Details
.valid_data?(data) ⇒ Boolean
21 22 23 24 25 26 |
# 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 |
Instance Method Details
#get_length ⇒ Object
17 18 19 |
# File 'lib/rqrcode/qrcode/qr_alphanumeric.rb', line 17 def get_length @data.size end |
#write(buffer) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |