Class: RQRCode::Export::SVG::Rect

Inherits:
BaseOutputSVG show all
Defined in:
lib/rqrcode/export/svg.rb

Instance Attribute Summary

Attributes inherited from BaseOutputSVG

#result

Instance Method Summary collapse

Methods inherited from BaseOutputSVG

#initialize

Constructor Details

This class inherits a constructor from RQRCode::Export::SVG::BaseOutputSVG

Instance Method Details

#build(module_size, options = {}) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/rqrcode/export/svg.rb', line 169

def build(module_size, options = {})
  # Extract values from options
  color = options[:color]
  offset_x = options[:offset_x].to_i
  offset_y = options[:offset_y].to_i

  @qrcode.modules.each_index do |c|
    @qrcode.modules.each_index do |r|
      next unless @qrcode.checked?(c, r)

      x = r * module_size + offset_x
      y = c * module_size + offset_y
      @result << %(<rect width="#{module_size}" height="#{module_size}" x="#{x}" y="#{y}" fill="#{color}"/>)
    end
  end
end