Class: MacOS::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/macos/display.rb

Overview

Simulates a macOS display.

Defined Under Namespace

Classes: Size

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:) ⇒ Display

Returns a new instance of Display.

Parameters:

  • id (Integer)

    d [Integer



14
15
16
# File 'lib/macos/display.rb', line 14

def initialize(id:)
  @id = id
end

Class Method Details

.mainObject



8
9
10
11
# File 'lib/macos/display.rb', line 8

def self.main
  id = Library.CGMainDisplayID
  new(id:)
end

Instance Method Details

#boundsSize

Returns:



19
20
21
22
23
24
25
26
# File 'lib/macos/display.rb', line 19

def bounds
  bounds = Library.CGDisplayBounds(@id)

  width = Integer(bounds[:size][:width])
  height = Integer(bounds[:size][:height])

  Size.new(width, height)
end

#screenshot {|tempfile| ... } ⇒ Object

Yields:

  • (tempfile)

Yield Parameters:

  • tempfile (Tempfile)


30
31
32
33
34
35
36
37
# File 'lib/macos/display.rb', line 30

def screenshot
  tempfile = Tempfile.new(["screenshot", ".png"])
  system("screencapture -o -x #{tempfile.path}")
  yield tempfile
ensure
  tempfile.close
  tempfile.unlink
end