Class: TianjiQRCodePNG::Sequence

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qr_code) ⇒ Sequence

Returns a new instance of Sequence.



5
6
7
# File 'lib/tianji_qrcode_png/sequence.rb', line 5

def initialize(qr_code)
  @qr_code = qr_code
end

Instance Attribute Details

#borderObject

Returns the value of attribute border.



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

def border
  @border
end

Instance Method Details

#border_widthObject

Returns the border, 1/10 of the img size



26
27
28
# File 'lib/tianji_qrcode_png/sequence.rb', line 26

def border_width()
  @border ||= img_size() / 10
end

#dark_squares_only(&block) ⇒ Object

This method yields the vertices of the dark squares



10
11
12
13
14
15
16
17
18
# File 'lib/tianji_qrcode_png/sequence.rb', line 10

def dark_squares_only(&block)
  @qr_code.modules.each_index do |row|
    @qr_code.modules.each_index do |column|
      if @qr_code.dark?(row, column)
        yield row, column
      end
    end
  end
end

#img_sizeObject

returns the image size by looking at how long the first line of the code is



21
22
23
# File 'lib/tianji_qrcode_png/sequence.rb', line 21

def img_size
  @img_size ||= @qr_code.to_s.split("\n").first.size()
end