Class: Sevgi::Graphics::Canvas
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Canvas
- Extended by:
- Forwardable
- Defined in:
- lib/sevgi/graphics/auxilary/canvas.rb
Instance Attribute Summary collapse
-
#inner ⇒ Object
readonly
Returns the value of attribute inner.
-
#margin ⇒ Object
readonly
Returns the value of attribute margin.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #conforming ⇒ Object
-
#initialize(width:, height:, unit: "mm", name: :custom, margins: []) ⇒ Canvas
constructor
A new instance of Canvas.
- #viewbox(origin = Undefined) ⇒ Object
- #viewport ⇒ Object
- #with(**kwargs) ⇒ Object
Constructor Details
#initialize(width:, height:, unit: "mm", name: :custom, margins: []) ⇒ Canvas
Returns a new instance of Canvas.
26 27 28 29 30 31 32 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 26 def initialize(width:, height:, unit: "mm", name: :custom, margins: []) @size = Paper[width, height, unit, name] @margin = Margin[*margins] compute freeze end |
Instance Attribute Details
#inner ⇒ Object (readonly)
Returns the value of attribute inner.
24 25 26 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 24 def inner @inner end |
#margin ⇒ Object (readonly)
Returns the value of attribute margin.
24 25 26 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 24 def margin @margin end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
24 25 26 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 24 def size @size end |
Class Method Details
.call(arg = Undefined, **kwargs) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 8 def self.call(arg = Undefined, **kwargs) case arg when Undefined new(**kwargs) when ::Symbol, ::String new(**Paper.public_send(arg).to_h, **kwargs) else ArgumentError.("Argument must be a Paper symbol: #{arg}") end end |
Instance Method Details
#attributes ⇒ Object
34 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 34 def attributes(...) = {**, viewBox: viewbox(...)} |
#conforming ⇒ Object
36 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 36 def conforming(...) = self.class.conforming(self, ...) |
#viewbox(origin = Undefined) ⇒ Object
40 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 40 def viewbox(origin = Undefined) = prettify(*originate(origin), width, height).join(" ") |
#viewport ⇒ Object
38 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 38 def = {width: "#{width}#{unit}", height: "#{height}#{unit}"} |
#with(**kwargs) ⇒ Object
42 |
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 42 def with(**kwargs) = self.class.new(**size.to_h, margins: kwargs.fetch(:margins, margin.to_a)) |