Class: Fastlane::QRGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/polidea/helper/qr_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, auto_awesome = false, dark_color = ::ChunkyPNG::Color::BLACK) ⇒ QRGenerator

Returns a new instance of QRGenerator.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/fastlane/plugin/polidea/helper/qr_generator.rb', line 5

def initialize(data, auto_awesome = false, dark_color = ::ChunkyPNG::Color::BLACK)
  @qr_code = RQRCode::QRCode.new(data, size: 10, level: :m)
  @auto_awesome = auto_awesome
  @dark_color = dark_color

  @margin = 20
  @image = ::ChunkyPNG::Image.new(2 * @margin + @qr_code.qrcode.module_count * 5, 2 * @margin + @qr_code.qrcode.module_count * 5, ::ChunkyPNG::Color::WHITE)

  @logo = ::ChunkyPNG::Image.from_file("#{path_to_resources}/logo.png")
  @logo = @logo.resize(2 * @margin + @qr_code.qrcode.module_count * 5, 2 * @margin + @qr_code.qrcode.module_count * 5)
end

Instance Method Details

#generate(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fastlane/plugin/polidea/helper/qr_generator.rb', line 17

def generate(path)
  white = ::ChunkyPNG::Color::WHITE
  blue = ::ChunkyPNG::Color.rgb(26, 159, 217)

  if !@auto_awesome
    dark_color = @dark_color
  else
    dark_color = blue
  end

  @qr_code.modules.each_index do |row|
    @qr_code.modules[row].each_index do |column|
      if @qr_code.modules[row][column]
        print_symbol(dark_color, column, row, (column < 8 && row < 8) || (column < 8 && row >= @qr_code.qrcode.module_count - 8) || (column >= @qr_code.qrcode.module_count - 8 && row < 8))
      else
        print_symbol(white, column, row, (column < 8 && row < 8) || (column < 8 && row >= @qr_code.qrcode.module_count - 8) || (column >= @qr_code.qrcode.module_count - 8 && row < 8))
      end
    end
  end
  @image.save(path)
end