Class: Grcode::QRCode

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, options = {}) ⇒ QRCode

Returns a new instance of QRCode.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/grcode.rb', line 5

def initialize(string, options={})
  unless string.is_a? String
    raise "GRCode expected an String, but it found a #{string.class}"
  end
  
  url_options = {}
  url_options[:cht] = 'qr' # Tell google we want a QRCode
  url_options[:chl] = string
  url_options[:chs] = options[:size] ? "#{options[:size]}x#{options[:size]}" : '150x150'
  if options[:encoding]
    url_options[:choe] = options[:encoding]
  end
  
  if options[:correction] || options[:margin]
    correction = options[:correction] || 'L'
    margin = options[:margin] || '4'
    url_options[:chld] = "#{correction}|#{margin}"
  end
  
  @url = make_url(url_options)
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/grcode.rb', line 3

def url
  @url
end