module RQRCode::Export::SVG

def as_svg(options = {})


(default {})
svg_attributes - A optional hash of custom attributes. Existing attributes will remain.
(default false)
viewbox - replace `width` and `height` in with a viewBox, allows CSS scaling
(default false)
and quality. This will become the default in future versions.
use_path - Use to render SVG rather than to significantly reduce size
(default true)
standalone - Whether to make this a full SVG file, or only an svg to embed in other svg
(defaults crispEdges)
shape_rendering - SVG Attribute: auto | optimizeSpeed | crispEdges | geometricPrecision
(defaults 11)
module_size - The Pixel size of each module
(default "000")
color - Foreground color e.g "000"
(default none)
fill - Background color e.g "ffffff"
(default 0)
offset - Padding around the QR Code in pixels
Options:

Render the SVG from the Qrcode.
def as_svg(options = {})
  fill = options[:fill]
  use_path = options[:use_path]
  offset = options[:offset].to_i || 0
  color = options[:color] || "000"
  shape_rendering = options[:shape_rendering] || "crispEdges"
  module_size = options[:module_size] || 11
  standalone = options[:standalone].nil? ? true : options[:standalone]
  viewbox = options[:viewbox].nil? ? false : options[:viewbox]
  svg_attributes = options[:svg_attributes] || {}
  # height and width dependent on offset and QR complexity
  dimension = (@qrcode.module_count * module_size) + (2 * offset)
  # use dimensions differently if we are using a viewBox
  dimensions_attr = viewbox ? %(viewBox="0 0 #{dimension} #{dimension}") : %(width="#{dimension}" height="#{dimension}")
  svg_tag_attributes = (DEFAULT_SVG_ATTRIBUTES + [
    dimensions_attr,
    %(shape-rendering="#{shape_rendering}")
  ] + svg_attributes.map { |k, v| %(#{k}="#{v}") }).join(" ")
  xml_tag = %(<?xml version="1.0" standalone="yes"?>)
  open_tag = %(<svg #{svg_tag_attributes}>)
  close_tag = "</svg>"
  output_tag = (use_path ? Path : Rect).new(@qrcode)
  output_tag.build(module_size, offset, color)
  if fill
    # Prefix hexadecimal colors unless using a named color (symbol)
    fill = "##{fill}" unless fill.is_a?(Symbol)
    output_tag.result.unshift %(<rect width="#{dimension}" height="#{dimension}" x="0" y="0" fill="#{fill}"/>)
  end
  if standalone
    output_tag.result.unshift(xml_tag, open_tag)
    output_tag.result << close_tag
  end
  output_tag.result.join
end