Class: RQRCode::QRCode

Inherits:
Object
  • Object
show all
Defined in:
lib/rqrcode/qrcode/qr_code.rb

Overview

This is the main interface for creating your QRCode You create a new instance of QRCode and then you have a few simple methods to choose form

Constant Summary collapse

PAD0 =
0xEC
PAD1 =
0x11

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ QRCode

Expects a string to be parsed in, other options have defaults



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rqrcode/qrcode/qr_code.rb', line 56

def initialize( *args )
			raise QRCodeArgumentError unless args.first.kind_of?( String )

			@data									= args.shift
			options								= args.extract_options!
  level									= options[:level] || :h 
  @error_correct_level  = QRERRORCORRECTLEVEL[ level.to_sym ] 
  @type_number	        = options[:size] || 4
			@module_count					= @type_number * 4 + 17
  @modules							= nil
  @data_cache						= nil
			@data_list						= QR8bitByte.new( @data )

			self.make # let's go !
end

Instance Attribute Details

#module_countObject (readonly)

Returns the value of attribute module_count.



49
50
51
# File 'lib/rqrcode/qrcode/qr_code.rb', line 49

def module_count
  @module_count
end

#modulesObject (readonly)

Returns the value of attribute modules.



49
50
51
# File 'lib/rqrcode/qrcode/qr_code.rb', line 49

def modules
  @modules
end

Instance Method Details

#is_dark(row, col) ⇒ Object

called parsing in a row and col coordinate

  • return true or false

  • raise exception if row < 0

  • raise exception if col < 0

  • raise exception if @module_count <= row

  • raise exception if @module_count <= col



79
80
81
82
83
84
# File 'lib/rqrcode/qrcode/qr_code.rb', line 79

def is_dark( row, col )
  if row < 0 || @module_count <= row || col < 0 || @module_count <= col
    raise QRCodeRunTimeError, "#{row},#{col}"
  end
  @modules[row][col]
end

#to_consoleObject



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rqrcode/qrcode/qr_code.rb', line 86

def to_console
  (0...@module_count).each do |col|
    tmp = []
    (0...@module_count).each do |row|
      if is_dark(col,row)
        tmp << "x"
      else
        tmp << " "
      end
    end 
    puts tmp.join
  end
end