Class: Laser::Cutter::Renderer::SvgRenderer
- Defined in:
- lib/laser/cutter/renderer/svg_renderer.rb
Overview
Writes the box as an SVG sized in the configuration's own units. It
fits the page to the box, and carries the metadata as a
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#config, #enclosure, #page_manager, #subject
Instance Method Summary collapse
-
#document ⇒ String
The SVG, yielding after each line drawn.
-
#initialize(config) ⇒ SvgRenderer
constructor
A new instance of SvgRenderer.
-
#lines ⇒ Array<Geometry::Line>
Every line to cut, computed once.
-
#total ⇒ Integer
How many lines Base#render draws, and yields.
Methods inherited from Base
Constructor Details
#initialize(config) ⇒ SvgRenderer
Returns a new instance of SvgRenderer.
13 14 15 16 |
# File 'lib/laser/cutter/renderer/svg_renderer.rb', line 13 def initialize(config) super self.subject = Laser::Cutter::BoxFactory.for(config) end |
Instance Method Details
#document ⇒ String
Returns the SVG, yielding after each line drawn.
29 30 31 32 33 34 35 36 37 |
# File 'lib/laser/cutter/renderer/svg_renderer.rb', line 29 def document svg = Victor::SVG.new(width: "#{width}#{units}", height: "#{height}#{units}", viewBox: "0 0 #{width} #{height}") svg.element(:desc, description) if config. lines.each do |line| svg.line(**coordinates(line), stroke: "##{config[:color] || BLACK}", stroke_width: config.stroke) yield line if block_given? end svg.render end |
#lines ⇒ Array<Geometry::Line>
Returns every line to cut, computed once.
19 20 21 |
# File 'lib/laser/cutter/renderer/svg_renderer.rb', line 19 def lines @lines ||= subject.generate_notches end |
#total ⇒ Integer
Returns how many lines Base#render draws, and yields.
24 25 26 |
# File 'lib/laser/cutter/renderer/svg_renderer.rb', line 24 def total lines.size end |