Module: RQRCode

Defined in:
lib/rqrcode/renderer.rb,
lib/rqrcode/renderer/version.rb

Defined Under Namespace

Modules: Renderer

Constant Summary collapse

LEVELS =
%w(l m q h).freeze
SIZES =
(1..40).to_a.freeze
CAPACITY =

CAPACITY = Hash[LEVELS.map { |level| [level, [nil] * SIZES.length] }] SIZES.each { |size| LEVELS.each { |level| next if CAPACITY[size - 1]; string = “a” * (CAPACITY[size - 2] || 0); begin; loop { QRCode.new(string << “a”, size: size, level: level) }; rescue QRCodeRunTimeError; CAPACITY[size - 1] = string.length; puts “#size#level: #[size - 1]”; end } }

{"l"=>[18, 33, 54, 79, 107, 135, 155, 193, 231, 272, 322, 368, 426, 459, 521, 587, 645, 719, 793, 859, 930, 1004, 1092, 1172, 1274, 1368, 1466, 1529, 1629, 1733, 1841, 1953, 2069, 2189, 2304, 2432, 2564, 2700, 2810, 2954], "m"=>[15, 27, 43, 63, 85, 107, 123, 153, 181, 214, 252, 288, 332, 363, 413, 451, 505, 561, 625, 667, 712, 780, 858, 912, 998, 1060, 1126, 1191, 1265, 1371, 1453, 1539, 1629, 1723, 1810, 1912, 1990, 2100, 2214, 2332], "q"=>[12, 21, 33, 47, 61, 75, 87, 109, 131, 152, 178, 204, 242, 259, 293, 323, 365, 395, 443, 483, 510, 566, 612, 662, 716, 752, 806, 869, 909, 983, 1031, 1113, 1169, 1229, 1284, 1352, 1424, 1500, 1580, 1664], "h"=>[8, 15, 25, 35, 45, 59, 65, 85, 99, 120, 138, 156, 178, 195, 196, 251, 281, 311, 339, 383, 404, 440, 462, 512, 536, 594, 626, 659, 699, 743, 791, 843, 899, 959, 984, 1052, 1094, 1140, 1220, 1274]}.with_indifferent_access.freeze

Class Method Summary collapse

Class Method Details

.size_for(string, level = :h) ⇒ Object



11
12
13
14
# File 'lib/rqrcode/renderer.rb', line 11

def self.size_for string, level=:h
  length = string.length
  SIZES.find { |size| CAPACITY[level][size - 1] > length }
end