Class: Kleya::Viewport

Inherits:
Object
  • Object
show all
Defined in:
lib/kleya/viewport.rb

Overview

Viewport dimensions

Examples:

Creating a viewport

Kleya::Viewport.new(width: 1200, height: 675) # => #<Viewport @width=1200 @height=675>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width:, height:) ⇒ Viewport

Returns a new instance of Viewport.

Parameters:

  • width (Integer)

    the width of the viewport

  • height (Integer)

    the height of the viewport



10
11
12
13
# File 'lib/kleya/viewport.rb', line 10

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

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



6
7
8
# File 'lib/kleya/viewport.rb', line 6

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



6
7
8
# File 'lib/kleya/viewport.rb', line 6

def width
  @width
end

Instance Method Details

#==(other) ⇒ Boolean

Returns whether the viewports are equal.

Parameters:

  • other (Viewport)

    the other viewport

Returns:

  • (Boolean)

    whether the viewports are equal



27
28
29
# File 'lib/kleya/viewport.rb', line 27

def ==(other)
  other.is_a?(Viewport) && width == other.width && height == other.height
end

#inspectString

Returns the inspection of the viewport.

Returns:

  • (String)

    the inspection of the viewport



32
33
34
# File 'lib/kleya/viewport.rb', line 32

def inspect
  "#<#{self.class.name} @width=#{width} @height=#{height}>"
end

#to_aArray

Returns the viewport dimensions.

Returns:

  • (Array)

    the viewport dimensions



21
22
23
# File 'lib/kleya/viewport.rb', line 21

def to_a
  [width, height]
end

#to_hHash

Returns the viewport dimensions.

Returns:

  • (Hash)

    the viewport dimensions



16
17
18
# File 'lib/kleya/viewport.rb', line 16

def to_h
  { width:, height: }
end