Module: RQRCode::Export::HTML

Included in:
QRCode
Defined in:
lib/rqrcode/export/html.rb

Constant Summary collapse

TABLE_OPEN =
"<table>"
TABLE_CLOSE =
"</table>"
TR_OPEN =
"<tr>"
TR_CLOSE =
"</tr>"
TD_BLACK =
'<td class="black"></td>'
TD_WHITE =
'<td class="white"></td>'

Instance Method Summary collapse

Instance Method Details

#as_htmlObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rqrcode/export/html.rb', line 13

def as_html
  qr = @qrcode
  module_count = qr.module_count

  estimated_size = (module_count * module_count * 26) + (module_count * 9) + 15
  result = String.new(capacity: estimated_size)

  result << TABLE_OPEN
  module_count.times do |row_index|
    result << TR_OPEN
    module_count.times do |col_index|
      result << (qr.checked?(row_index, col_index) ? TD_BLACK : TD_WHITE)
    end
    result << TR_CLOSE
  end
  result << TABLE_CLOSE

  result
end