Class: RQREncoder::QREncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/rqrencoder/qr_encoder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ QREncoder

options

:version 		will auto-extend if too low (default)
:level       L:0, M:1(default), Q:2, H:3
:mode				hint for mode NUM:0, A/N:1 (default), 8Bit: 2, KANJI: 3
:case_sensitive true(default) / false


10
11
12
13
# File 'lib/rqrencoder/qr_encoder.rb', line 10

def initialize(options = {})
	@options = { :level => 1, :version => 0, :mode => 2, :case_sensitive => true }
   @options.merge!(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rqrencoder/qr_encoder.rb', line 25

def method_missing(sym, *args, &block)
  if (sym[-1] == '=')
key = sym[0..-2].to_sym
super(sym, *args, &block) unless (@options.has_key? key)
    @options[key] = args[0]
  end
end

Class Method Details

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

Yields:

  • (encoder)


19
20
21
22
23
# File 'lib/rqrencoder/qr_encoder.rb', line 19

def self.create(options = {})
  encoder = QREncoder.new(options)
  yield encoder if block_given?
  encoder
end

Instance Method Details

#encode(data) ⇒ Object



33
34
35
36
# File 'lib/rqrencoder/qr_encoder.rb', line 33

def encode(data)
			c_code_result = RQREncoder.QRcode_encodeString(data, @options[:version], @options[:level], @options[:mode], @options[:case_sensitive] ? 1 : 0) 
  QRCode.new(data, @options[:level], c_code_result.version, c_code_result.width, c_code_result.modules)
end

#optionsObject



15
16
17
# File 'lib/rqrencoder/qr_encoder.rb', line 15

def options
  @options
end