Class: MacOS::Display
- Inherits:
-
Object
- Object
- MacOS::Display
- Defined in:
- lib/macos/display.rb
Overview
Simulates a macOS display.
Defined Under Namespace
Classes: Size
Class Method Summary collapse
Instance Method Summary collapse
- #bounds ⇒ Size
-
#initialize(id:) ⇒ Display
constructor
A new instance of Display.
- #screenshot {|tempfile| ... } ⇒ Object
Constructor Details
#initialize(id:) ⇒ Display
Returns a new instance of Display.
14 15 16 |
# File 'lib/macos/display.rb', line 14 def initialize(id:) @id = id end |
Class Method Details
.main ⇒ Object
8 9 10 11 |
# File 'lib/macos/display.rb', line 8 def self.main id = Library.CGMainDisplayID new(id:) end |
Instance Method Details
#bounds ⇒ Size
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
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 |