Class: Prawn::Qr::QRCode
- Inherits:
-
Object
- Object
- Prawn::Qr::QRCode
- Defined in:
- lib/prawn-qr/qrcode.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#document ⇒ Object
Returns the value of attribute document.
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(document, content) ⇒ QRCode
constructor
A new instance of QRCode.
- #qrcode ⇒ Object
Constructor Details
#initialize(document, content) ⇒ QRCode
Returns a new instance of QRCode.
8 9 10 11 |
# File 'lib/prawn-qr/qrcode.rb', line 8 def initialize(document, content) @document = document @content = content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/prawn-qr/qrcode.rb', line 6 def content @content end |
#document ⇒ Object
Returns the value of attribute document.
6 7 8 |
# File 'lib/prawn-qr/qrcode.rb', line 6 def document @document end |
Instance Method Details
#draw ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/prawn-qr/qrcode.rb', line 26 def draw document.fill_color 'ffffff' document.rectangle( [horizontal_offset, vertical_offset + table_size], table_size, table_size ) document.fill qrcode.reverse.each_with_index do |row, y| y += 1 row.each_with_index do |dark, x| if dark document.fill_color = '000000' document.rectangle( [x * cell_size + horizontal_offset, y * cell_size + vertical_offset], cell_size, cell_size ) document.fill end end end end |
#qrcode ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/prawn-qr/qrcode.rb', line 13 def qrcode return @qrcode if @qrcode size = 1 while(!@qrcode) begin @qrcode = RQRCode::QRCode.new(content, size: size) rescue RQRCode::QRCodeRunTimeError size += 1 end end @qrcode = @qrcode.modules end |