Class: QREncoder::PNG

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qrcode, options = {}) ⇒ PNG

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

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



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

#backgroundObject (readonly)

Returns the value of attribute background



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

def background
  @background
end

#canvasObject (readonly)

Returns the value of attribute canvas



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

def canvas
  @canvas
end

#marginObject (readonly)

Returns the value of attribute margin



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

def margin
  @margin
end

#pixels_per_moduleObject (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

#pointsObject (readonly)

Returns the value of attribute points



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

def points
  @points
end

#widthObject (readonly)

Returns the value of attribute width



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

def width
  @width
end

Instance Method Details

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


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

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