Class: RQR::QRCode

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ QRCode

options

:level       L:0, M:1(default), Q:2, H:3
:version     S:0(default), M:1, L:2
:auto_extend  true(default)|false auto extent if over version size
:masking     masking pattern 0-7, -1(default auto)
:length      data length
:module_size module pixel size
:eps_preview true|false(default)


12
13
14
15
16
17
# File 'lib/rqr/qrcode.rb', line 12

def initialize(options = {})
	@options = { :level => 1, :version => 0, :auto_extend => true, 
	             :masking => -1, :eps_preview => false, :module_size => 4 }
   @options.merge!(options)
   @imager = nil
end

Class Method Details

.create(options = {}) {|qrcode| ... } ⇒ Object

Yields:

  • (qrcode)

Raises:



19
20
21
22
23
24
# File 'lib/rqr/qrcode.rb', line 19

def self.create(options = {})
  raise BlockNotFoundException.new("Block not found!") unless block_given?
  qrcode = RQR::QRCode.new(options)
  yield qrcode
  qrcode.close
end

Instance Method Details

#closeObject



54
55
56
57
# File 'lib/rqr/qrcode.rb', line 54

def close()
  @encoder = nil if @encoder
  (@imager.close; @imager = nil) if @imager
end

#save(data, path, format = nil) ⇒ Object

data

data for qrcode

path

path for qrcode image file

format

image format. :jpg|:png|:tiff|:eps



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rqr/qrcode.rb', line 29

def save(data, path, format=nil)
	format ||= get_format(path)

init_encoder(data)

	case format.to_sym
		when :jpg, :jpeg
			res = save_as_jpeg(path)
		when :png
			res = save_as_png(path)
		when :tiff, :tif
			res = save_as_tiff(path)
		when :eps
			res = save_as_eps(path)
		else
		  close; raise RQR::FormatNotFoundException.new("invalid format! #{format}")
	end
   
   close
   
   if res != 0
     raise RQR::ImageException.new("qrcode image error! #{path} wasn't created.")
	end
end