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



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rqrcode/export/svg.rb', line 92

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

  # 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|
      x = r * module_size + offset_x
      y = c * module_size + offset_y

      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