module RQRCode::SizeCalculator

Constants

QR_CHAR_SIZE_VS_SIZE

size - seems to follow this logic

# | input | modules 
  | size  | created

Public Instance Methods

minimum_qr_size_from_string(string) click to toggle source
# File lib/rqrcode-rails3/size_calculator.rb, line 24
def minimum_qr_size_from_string(string)
  QR_CHAR_SIZE_VS_SIZE.each_with_index do |size, index|
    return (index + 1) if string.size < size
  end
  
  # If it's particularly big, we'll try and create codes until it accepts
  i = QR_CHAR_SIZE_VS_SIZE.size
  begin
    i += 1
    RQRCode::QRCode.new(string, :size => i)
    return i
  rescue RQRCode::QRCodeRunTimeError
    retry
  end
end