Class: QREncoder::PNG

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (PNG) initialize(qrcode, options = {})

Takes an optional hash of options. See QRCode#png for details.



14
15
16
17
18
19
20
21
22
23
# File 'lib/qrencoder/png.rb', line 14

def initialize(qrcode, options={})
  @points = qrcode.points
  @margin = options[:margin] || 4
  @pixels_per_module= options[:pixels_per_module] || 1
  @background = options[:transparent] ? ChunkyPNG::Color::TRANSPARENT : ChunkyPNG::Color::WHITE
  @width = (qrcode.width + (2 * margin)) * pixels_per_module

  @canvas = ChunkyPNG::Image.new(width, width, background)
  plot_points
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block)



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

def method_missing(method, *args, &block)
  if canvas.respond_to?(method)
    canvas.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

- (Object) background (readonly)

Returns the value of attribute background



5
6
7
# File 'lib/qrencoder/png.rb', line 5

def background
  @background
end

- (Object) canvas (readonly)

Returns the value of attribute canvas



5
6
7
# File 'lib/qrencoder/png.rb', line 5

def canvas
  @canvas
end

- (Object) margin (readonly)

Returns the value of attribute margin



5
6
7
# File 'lib/qrencoder/png.rb', line 5

def margin
  @margin
end

- (Object) pixels_per_module (readonly)

Returns the value of attribute pixels_per_module



5
6
7
# File 'lib/qrencoder/png.rb', line 5

def pixels_per_module
  @pixels_per_module
end

- (Object) points (readonly)

Returns the value of attribute points



5
6
7
# File 'lib/qrencoder/png.rb', line 5

def points
  @points
end

- (Object) width (readonly)

Returns the value of attribute width



5
6
7
# File 'lib/qrencoder/png.rb', line 5

def width
  @width
end

Instance Method Details

- (Boolean) respond_to?(method)



33
34
35
# File 'lib/qrencoder/png.rb', line 33

def respond_to?(method)
  super || canvas.respond_to?(method)
end