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
-
.define(name, **spec) ⇒ Sevgi::Graphics::Paper
Defines or replaces a named paper profile.
-
.exist?(name) ⇒ Boolean
Reports whether a 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) ⇒ 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) ⇒ void
Creates a paper profile.
25 26 27 28 29 30 31 32 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 25 def initialize(width:, height:, unit: "mm", name: :custom) super( width: self.class.send(:dimension!, :width, width), height: self.class.send(:dimension!, :height, height), unit: self.class.send(:symbol!, :unit, unit), name: self.class.send(:symbol!, :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
.define(name, **spec) ⇒ Sevgi::Graphics::Paper
Defines or replaces a named paper profile.
73 74 75 76 77 78 79 80 81 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 73 def self.define(name, **spec) name = symbol!(:name, name) ArgumentError.("Paper name is reserved: #{name}") if reserved?(name) && !exist?(name) singleton_class.remove_method(name) if singleton_class.method_defined?(name, false) singleton_class.attr_reader(name) profiles[name] = instance_variable_set("@#{name}", new(name:, **spec)) end |
.exist?(name) ⇒ Boolean
Reports whether a named paper profile exists.
63 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 63 def self.exist?(name) = name.respond_to?(:to_sym) && profiles.key?(name.to_sym) |
Instance Method Details
#<=>(other) ⇒ Integer?
Compares papers by width, height, unit, then name.
37 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 37 def <=>(other) = deconstruct <=> other.deconstruct |
#eql?(other) ⇒ Boolean Also known as: ==
Reports strict paper equality.
42 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 42 def eql?(other) = self.class == other.class && deconstruct == other.deconstruct |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
46 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 46 def hash = [self.class, *deconstruct].hash |
#longest ⇒ Float
Returns the longer side.
50 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 50 def longest = [width, height].max |
#shortest ⇒ Float
Returns the shorter side.
54 |
# File 'lib/sevgi/graphics/auxiliary/paper.rb', line 54 def shortest = [width, height].min |