class HealthCards::ChunkCore::SHCQRCode

RQRCodeCore data shim for multimode encoding

Constants

MULTI_REGEX
NUMBER_LENGTH
SINGLE_REGEX

Public Class Methods

new(data) click to toggle source
# File lib/health_cards/chunk.rb, line 47
def initialize(data)
  @data = data
end

Public Instance Methods

write(buffer) click to toggle source
# File lib/health_cards/chunk.rb, line 51
def write(buffer)
  multi = MULTI_REGEX.match(@data)
  prefix = multi ? multi.to_s : SINGLE_REGEX.match(@data).to_s

  buffer.byte_encoding_start(prefix.length)

  prefix.each_byte do |b|
    buffer.put(b, 8)
  end

  num_content = @data.delete_prefix(prefix)

  buffer.numeric_encoding_start(num_content.length)

  num_content.size.times do |i|
    next unless (i % 3).zero?

    chars = num_content[i, 3]
    bit_length = get_bit_length(chars.length)
    buffer.put(get_code(chars), bit_length)
  end
end

Private Instance Methods

get_bit_length(length) click to toggle source
# File lib/health_cards/chunk.rb, line 82
def get_bit_length(length)
  NUMBER_LENGTH[length]
end
get_code(chars) click to toggle source
# File lib/health_cards/chunk.rb, line 86
def get_code(chars)
  chars.to_i
end