2 def key_svg_tag(**options)
3 border_width = options["border"] ? (options["border-width"] || 1) : 0
7 :fill => options["fill"] || "none"
9 if border_width.positive?
10 rect_attrs[:x] = rect_attrs[:y] = format("%g", 0.5 * border_width)
11 rect_attrs[:width] = options["width"] - border_width
12 rect_attrs[:height] = options["height"] - border_width
14 svg_attrs = options.slice("width", "height", "opacity", :class)
16 tag.svg(**svg_attrs) do
17 horizontal = "H#{options['width']}"
18 concat tag.rect(**rect_attrs, **stroke_attrs(options, "border")) if options["fill"] || options["border"]
20 y_middle = format("%g", 0.5 * options["height"])
21 concat tag.path(:d => "M0,#{y_middle} #{horizontal}", **stroke_attrs(options, "line"))
24 casing_width = options["casing-width"] || 1
25 y_top = format("%g", 0.5 * casing_width)
26 y_bottom = format("%g", options["height"] - (0.5 * casing_width))
27 concat tag.path(:d => "M0,#{y_top} #{horizontal} M0,#{y_bottom} #{horizontal}", **stroke_attrs(options, "casing"))
34 def stroke_attrs(attrs, prefix)
35 attrs.select { |key| key.start_with?(prefix) }.transform_keys { |key| key.delete_prefix(prefix).prepend("stroke") }