Parent

QRTools::QRCode

Public Class Methods

decode(*args, &block) click to toggle source

(Not documented)

# File lib/qrtools/qrcode.rb, line 7
      def decode *args, &block
        Decoder.decode *args, &block
      end
encode(*args, &block) click to toggle source

(Not documented)

# File lib/qrtools/qrcode.rb, line 11
      def encode *args, &block
        Encoder.encode *args, &block
      end

Public Instance Methods

to_matrix() click to toggle source

(Not documented)

# File lib/qrtools/qrcode.rb, line 16
    def to_matrix
      codes = []
      data.unpack("C#{width ** 2}").each_slice(width) { |row|
        codes << row.map { |x| x & 0x1 == 1 }
      }
      codes
    end
to_png(scale = 4, border = 10) click to toggle source

(Not documented)

# File lib/qrtools/qrcode.rb, line 30
    def to_png scale = 4, border = 10
      # Add 2 extra rows / columns for white borders
      size = (width + border) * scale
      canvas = PNG::Canvas.new(size, size, PNG::Color::White)

      scaled_matrix = []
      to_matrix.each do |row|
        scaled_row = row.map { |bit|
          [bit] * scale
        }.flatten
        scaled_matrix += ([scaled_row] * scale)
      end

      factor = border / 2 * scale
      scaled_matrix.each_with_index { |row, i|
        x = i + factor
        row.each_with_index { |bit, j|
          y = j + factor
          canvas[x, y] = bit ? PNG::Color::Black : PNG::Color::White 
        }
      }
      PNG.new(canvas).to_blob
    end
to_s() click to toggle source

(Not documented)

# File lib/qrtools/qrcode.rb, line 24
    def to_s
      to_matrix.map { |row|
        row.map { |bit| bit ? '#' : ' ' }.join
      }.join("\n")
    end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.