Class: VisualQrcode::Qrcode
- Inherits:
-
Object
- Object
- VisualQrcode::Qrcode
- Includes:
- ModuleFiller, PixelTools
- Defined in:
- lib/visual_qrcode/qrcode.rb
Constant Summary collapse
- DEFAULT_PADDING_MODULES =
7
Constants included from ModuleFiller
ModuleFiller::PIXELS_PER_MODULE
Constants included from PixelTools
Instance Attribute Summary collapse
-
#basic_qrcode ⇒ Object
readonly
Returns the value of attribute basic_qrcode.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#pixels_handler ⇒ Object
readonly
Returns the value of attribute pixels_handler.
-
#vqr_pixels ⇒ Object
readonly
Returns the value of attribute vqr_pixels.
Instance Method Summary collapse
- #as_png(margin: default_margin) ⇒ Object
- #fill_vqr_pixels ⇒ Object
-
#initialize(content, image_path, size: nil, padding_modules: nil, minimum_qr_size: nil) ⇒ Qrcode
constructor
A new instance of Qrcode.
- #intit_vqr_pixels ⇒ Object
- #make ⇒ Object
- #resize_image ⇒ Object
Methods included from ModuleFiller
Methods included from PixelTools
#max_depth, #pixel_of, #pixel_of_color, #transparent_pixel, #white_pixel
Constructor Details
#initialize(content, image_path, size: nil, padding_modules: nil, minimum_qr_size: nil) ⇒ Qrcode
Returns a new instance of Qrcode.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/visual_qrcode/qrcode.rb', line 18 def initialize(content, image_path, size: nil, padding_modules: nil, minimum_qr_size: nil) @content = content @size = size @padding_modules = padding_modules || DEFAULT_PADDING_MODULES @minimum_qr_size = minimum_qr_size || 6 initialize_basic_qr_code_and_minimum_qr_size(content) @pixels_handler = VisualQrcode::PixelsHandler.new(image_path: image_path) @common_patterns = @basic_qrcode.instance_variable_get(:@common_patterns) end |
Instance Attribute Details
#basic_qrcode ⇒ Object (readonly)
Returns the value of attribute basic_qrcode.
16 17 18 |
# File 'lib/visual_qrcode/qrcode.rb', line 16 def basic_qrcode @basic_qrcode end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
16 17 18 |
# File 'lib/visual_qrcode/qrcode.rb', line 16 def content @content end |
#pixels_handler ⇒ Object (readonly)
Returns the value of attribute pixels_handler.
16 17 18 |
# File 'lib/visual_qrcode/qrcode.rb', line 16 def pixels_handler @pixels_handler end |
#vqr_pixels ⇒ Object (readonly)
Returns the value of attribute vqr_pixels.
16 17 18 |
# File 'lib/visual_qrcode/qrcode.rb', line 16 def vqr_pixels @vqr_pixels end |
Instance Method Details
#as_png(margin: default_margin) ⇒ Object
29 30 31 32 |
# File 'lib/visual_qrcode/qrcode.rb', line 29 def as_png(margin: default_margin) make VisualQrcode::Export.new(@vqr_pixels).as_png(size: @size, margin: margin) end |
#fill_vqr_pixels ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/visual_qrcode/qrcode.rb', line 50 def fill_vqr_pixels @basic_qrcode.modules.each_with_index do |module_row, x_index| module_row.each_index do |y_index| fill_vqr_module(x_index, y_index) end end end |
#intit_vqr_pixels ⇒ Object
40 41 42 43 |
# File 'lib/visual_qrcode/qrcode.rb', line 40 def intit_vqr_pixels @vqr_length = min_length * size_multiplier @vqr_pixels = Array.new(@vqr_length) { Array.new(@vqr_length) } end |
#make ⇒ Object
34 35 36 37 38 |
# File 'lib/visual_qrcode/qrcode.rb', line 34 def make intit_vqr_pixels resize_image fill_vqr_pixels end |
#resize_image ⇒ Object
45 46 47 48 |
# File 'lib/visual_qrcode/qrcode.rb', line 45 def resize_image padding_size = @padding_modules * module_size @pixels_handler.resize_with_padding(@vqr_length, padding_size) end |