Class: RQR::QRCode
- Inherits:
-
Object
- Object
- RQR::QRCode
- Defined in:
- lib/rqr/qrcode.rb
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(options = {}) ⇒ QRCode
constructor
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).
-
#save(data, path, format = nil) ⇒ Object
- data
- data for qrcode path
- path for qrcode image file format
-
image format.
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 = { :level => 1, :version => 0, :auto_extend => true, :masking => -1, :eps_preview => false, :module_size => 4 } @options.merge!() @imager = nil end |
Class Method Details
.create(options = {}) {|qrcode| ... } ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rqr/qrcode.rb', line 19 def self.create( = {}) raise BlockNotFoundException.new("Block not found!") unless block_given? qrcode = RQR::QRCode.new() yield qrcode qrcode.close end |
Instance Method Details
#close ⇒ Object
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 |