Class: RQRCode::QRBitBuffer
- Inherits:
-
Object
- Object
- RQRCode::QRBitBuffer
- Defined in:
- lib/rqrcode/qrcode/qr_bit_buffer.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
- #get(index) ⇒ Object
- #get_length_in_bits ⇒ Object
-
#initialize ⇒ QRBitBuffer
constructor
A new instance of QRBitBuffer.
- #put(num, length) ⇒ Object
- #put_bit(bit) ⇒ Object
Constructor Details
#initialize ⇒ QRBitBuffer
Returns a new instance of QRBitBuffer.
17 18 19 20 |
# File 'lib/rqrcode/qrcode/qr_bit_buffer.rb', line 17 def initialize @buffer = [] @length = 0 end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
15 16 17 |
# File 'lib/rqrcode/qrcode/qr_bit_buffer.rb', line 15 def buffer @buffer end |
Instance Method Details
#get(index) ⇒ Object
23 24 25 26 |
# File 'lib/rqrcode/qrcode/qr_bit_buffer.rb', line 23 def get( index ) buf_index = (index / 8).floor (( (@buffer[buf_index]).rszf(7 - index % 8)) & 1) == 1 end |
#get_length_in_bits ⇒ Object
36 37 38 |
# File 'lib/rqrcode/qrcode/qr_bit_buffer.rb', line 36 def get_length_in_bits @length end |
#put(num, length) ⇒ Object
29 30 31 32 33 |
# File 'lib/rqrcode/qrcode/qr_bit_buffer.rb', line 29 def put( num, length ) ( 0...length ).each do |i| put_bit((((num).rszf(length - i - 1)) & 1) == 1) end end |
#put_bit(bit) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rqrcode/qrcode/qr_bit_buffer.rb', line 41 def put_bit( bit ) buf_index = ( @length / 8 ).floor if @buffer.size <= buf_index @buffer << 0 end if bit @buffer[buf_index] |= ((0x80).rszf(@length % 8)) end @length += 1 end |