Class: Sevgi::Graphics::Paper

Inherits:
Data
  • Object
show all
Includes:
Comparable
Defined in:
lib/sevgi/graphics/auxilary/paper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width:, height:, unit: "mm", name: :custom) ⇒ Paper

Returns a new instance of Paper.



8
9
10
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 8

def initialize(width:, height:, unit: "mm", name: :custom)
  super(width: Float(width), height: Float(height), unit: unit.to_sym, name: name.to_sym)
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



5
6
7
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 5

def height
  @height
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 5

def name
  @name
end

#unitObject (readonly)

Returns the value of attribute unit

Returns:

  • (Object)

    the current value of unit



5
6
7
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 5

def unit
  @unit
end

#widthObject (readonly)

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



5
6
7
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 5

def width
  @width
end

Class Method Details

.define(name, **spec) ⇒ Object



32
33
34
35
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 32

def self.define(name, **spec)
  singleton_class.attr_reader(name)
  instance_variable_set("@#{name}", new(name:, **spec))
end

.define!(name) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 24

def self.define!(name, ...)
  raise ArgumentError, "Paper already defined: #{name}" if exist?(name)

  define(name, ...)
end

.exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


30
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 30

def self.exist?(name) = respond_to?(name)

Instance Method Details

#<=>(other) ⇒ Object



12
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 12

def <=>(other) = deconstruct <=> other.deconstruct

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


14
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 14

def eql?(other) = self.class == other.class && deconstruct == other.deconstruct

#hashObject



16
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 16

def hash = [self.class, *deconstruct].hash

#longestObject



18
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 18

def longest = [width, height].max

#shortestObject



20
# File 'lib/sevgi/graphics/auxilary/paper.rb', line 20

def shortest = [width, height].min