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, offset, color) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rqrcode/export/svg.rb', line 87

def build(module_size, offset, color)
  # Prefix hexadecimal colors unless using a named color (symbol)
  color = "##{color}" unless color.is_a?(Symbol)

  @qrcode.modules.each_index do |c|
    tmp = []
    @qrcode.modules.each_index do |r|
      y = c * module_size + offset
      x = r * module_size + offset

      next unless @qrcode.checked?(c, r)
      tmp << %(<rect width="#{module_size}" height="#{module_size}" x="#{x}" y="#{y}" fill="#{color}"/>)
    end

    @result << tmp.join
  end
end