QRCode objects expect only one required constructor parameter and an optional hash of any other. Here's a few examples:
qr = RQRCode::QRCode.new('hello world') qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
Expects a string to be parsed in, other args are optional
# string - the string you wish to encode # size - the size of the qrcode (default 4) # level - the error correction level, can be: * Level :l 7% of code can be restored * Level :m 15% of code can be restored * Level :q 25% of code can be restored * Level :h 30% of code can be restored (default :h) qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
# File lib/rqrcode/qrcode/qr_code.rb, line 86 def initialize( string, *args ) if !string.is_a? String raise QRCodeArgumentError, "The passed data is #{string.class}, not String" end options = args.extract_options! level = (options[:level] || :h).to_sym size = options[:size] || 4 if !QRERRORCORRECTLEVEL.has_key?(level) raise QRCodeArgumentError, "Unknown error correction level `#{level.inspect}`" end @data = string @error_correct_level = QRERRORCORRECTLEVEL[level] @version = size @module_count = @version * 4 + QRPOSITIONPATTERNLENGTH @modules = Array.new( @module_count ) @data_list = QR8bitByte.new( @data ) @data_cache = nil self.make end
is_dark is called with a col and row parameter. This will return true or false based on whether that coordinate exists in the matrix returned. It would normally be called while iterating through modules. A simple example would be:
instance.is_dark( 10, 10 ) => true
# File lib/rqrcode/qrcode/qr_code.rb, line 118 def is_dark( row, col ) if !row.between?(0, @module_count - 1) || !col.between?(0, @module_count - 1) raise QRCodeRunTimeError, "Invalid row/column pair: #{row}, #{col}" end @modules[row][col] end
This is a public method that returns the QR Code you have generated as a string. It will not be able to be read in this format by a QR Code reader, but will give you an idea if the final outout. It takes two optional args :true and :false which are there for you to choose how the output looks. Here’s an example of it’s use:
instance.to_s => xxxxxxx x x x x x xx xxxxxxx x x xxx xxxxxx xxx x x x xxx x xxxxx x xx x xxx x instance._to_s( :true => 'E', :false => 'Q') => EEEEEEEQEQQEQEQQQEQEQQEEQQEEEEEEE EQQQQQEQQEEEQQEEEEEEQEEEQQEQQQQQE EQEEEQEQQEEEEEQEQQQQQQQEEQEQEEEQE
# File lib/rqrcode/qrcode/qr_code.rb, line 145 def to_s( *args ) options = args.extract_options! row = options[:true] || 'x' col = options[:false] || ' ' res = [] @modules.each_index do |c| tmp = [] @modules.each_index do |r| if is_dark(c,r) tmp << row else tmp << col end end res << tmp.join end res.join("\n") end
Generated with the Darkfish Rdoc Generator 2.