Class: Sevgi::Graphics::Paper
- Inherits:
-
Data
- Object
- Data
- Sevgi::Graphics::Paper
- Includes:
- Comparable
- Defined in:
- lib/sevgi/graphics/auxiliary/paper.rb
Overview
Paper size and unit profile.
Instance Attribute Summary collapse
-
#height ⇒ Float
readonly
Paper height.
-
#name ⇒ Symbol
readonly
Profile name.
-
#unit ⇒ Symbol
readonly
SVG unit.
-
#width ⇒ Float
readonly
Paper width.
Class Method Summary collapse
-
.default ⇒ Sevgi::Graphics::Paper
Returns the default paper profile.
-
.define(name, overwrite: true, **spec) ⇒ Sevgi::Graphics::Paper
Defines a named paper profile after complete validation.
-
.exist?(name) ⇒ Boolean
Reports whether a normalizable named paper profile exists.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compares papers by width, height, unit, then name.
-
#eql?(other) ⇒ Boolean
(also: #==)
Reports strict paper equality.
-
#hash ⇒ Integer
Returns a hash compatible with strict equality.
-
#initialize(width:, height:, unit: "mm", name: :custom, **options) ⇒ void
constructor
Creates a paper profile.
-
#longest ⇒ Float
Returns the longer side.
-
#shortest ⇒ Float
Returns the shorter side.
Constructor Details
#initialize(width:, height:, unit: "mm", name: :custom, **options) ⇒ void
Creates a paper profile. Dimensions must be finite real numbers greater than zero.
26 27 28 29 30 31 32 33 34 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 26 def initialize(width:, height:, unit: "mm", name: :custom, **) self.class.send(:options!, ) super( width: self.class.send(:dimension!, :width, width), height: self.class.send(:dimension!, :height, height), unit: self.class.send(:normalize!, :unit, unit), name: self.class.send(:normalize!, :name, name) ) end |
Instance Attribute Details
#height ⇒ Float (readonly)
Returns paper height.
6 7 8 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 6 def height @height end |
#name ⇒ Symbol (readonly)
Returns profile name.
6 7 8 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 6 def name @name end |
#unit ⇒ Symbol (readonly)
Returns SVG unit.
6 7 8 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 6 def unit @unit end |
#width ⇒ Float (readonly)
Returns paper width.
6 7 8 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 6 def width @width end |
Class Method Details
.default ⇒ Sevgi::Graphics::Paper
Returns the default paper profile.
162 163 164 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 162 def self.default @mutex.synchronize { @profiles.fetch(:default) } end |
.define(name, overwrite: true, **spec) ⇒ Sevgi::Graphics::Paper
Defines a named paper profile after complete validation. Registration is process-global and thread-atomic.
Existing profiles are replaced by default; with overwrite: false, identical definitions return the canonical
profile and conflicting definitions raise. Names that are not Ruby call syntax remain accessible through
public_send.
87 88 89 90 91 92 93 94 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 87 def self.define(name, overwrite: true, **spec) name = normalize!(:name, name) ArgumentError.("Paper name is reserved: #{name}") if reserved?(name) overwrite = overwrite!(overwrite) profile = new(name:, **spec) register(name, profile, overwrite:) end |
.exist?(name) ⇒ Boolean
Reports whether a normalizable named paper profile exists. Invalid converters return false.
69 70 71 72 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 69 def self.exist?(name) name = normalize(name) name ? @mutex.synchronize { @profiles.key?(name) } : false end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compares papers by width, height, unit, then name.
39 40 41 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 39 def <=>(other) deconstruct <=> other.deconstruct if other.is_a?(self.class) end |
#eql?(other) ⇒ Boolean Also known as: ==
Reports strict paper equality.
46 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 46 def eql?(other) = self.class == other.class && deconstruct == other.deconstruct |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
50 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 50 def hash = [self.class, *deconstruct].hash |
#longest ⇒ Float
Returns the longer side.
54 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 54 def longest = [width, height].max |
#shortest ⇒ Float
Returns the shorter side.
58 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 58 def shortest = [width, height].min |