Class: IIIF::Image::Dimension

Inherits:
Object
  • Object
show all
Defined in:
lib/iiif/image/models/dimension.rb

Overview

Represents the size of a rectangle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(height:, width:) ⇒ Dimension

Returns a new instance of Dimension.



4
5
6
7
# File 'lib/iiif/image/models/dimension.rb', line 4

def initialize(height:, width:)
  @height = height
  @width = width
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



9
10
11
# File 'lib/iiif/image/models/dimension.rb', line 9

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/iiif/image/models/dimension.rb', line 9

def width
  @width
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
# File 'lib/iiif/image/models/dimension.rb', line 22

def ==(other)
  width == other.width && height == other.height
end

#aspectObject



26
27
28
# File 'lib/iiif/image/models/dimension.rb', line 26

def aspect
  Rational(width, height)
end

#enclosed_by?(other) ⇒ Boolean

Return true if both dimensions of other are greater

Returns:

  • (Boolean)


18
19
20
# File 'lib/iiif/image/models/dimension.rb', line 18

def enclosed_by?(other)
  width <= other.width && height <= other.height
end

#scale(scale) ⇒ Dimension

Parameters:

  • scale (Float)

    scale factor between 0 and 1

Returns:



13
14
15
# File 'lib/iiif/image/models/dimension.rb', line 13

def scale(scale)
  Dimension.new(height: height * scale, width: width * scale)
end