Class: Cejo::Ops::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/cejo/ops/screenshot.rb

Overview

Take a shot of the marvelous screen

Constant Summary collapse

SCREENSHOT_FORMAT =
'png'
FOLDER =
Pathname.new(Dir.home).join('Pictures')
CURRENT_TIME =
Time.new.strftime '%d-%m-%y-%I-%M'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(utils, mode) ⇒ Screenshot

Returns a new instance of Screenshot.



13
14
15
16
# File 'lib/cejo/ops/screenshot.rb', line 13

def initialize(utils, mode)
  @utils = utils
  @mode = mode.to_sym if mode
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



11
12
13
# File 'lib/cejo/ops/screenshot.rb', line 11

def mode
  @mode
end

#utilsObject (readonly)

Returns the value of attribute utils.



11
12
13
# File 'lib/cejo/ops/screenshot.rb', line 11

def utils
  @utils
end

Instance Method Details

#final_commandObject



63
64
65
# File 'lib/cejo/ops/screenshot.rb', line 63

def final_command
  "#{shotter[:bin]} #{shotter[mode]} #{shotter[:folder]}"
end

#flameshotObject



41
42
43
44
45
46
47
48
# File 'lib/cejo/ops/screenshot.rb', line 41

def flameshot
  {
    bin: 'flameshot',
    full: 'full -p',
    partial: 'gui -p',
    folder: FOLDER.to_path
  }
end

#maimObject



50
51
52
53
54
55
56
57
# File 'lib/cejo/ops/screenshot.rb', line 50

def maim
  {
    bin: 'maim',
    full: '',
    partial: '--select',
    folder: FOLDER.join(screenshot_name)
  }
end

#runObject



67
68
69
# File 'lib/cejo/ops/screenshot.rb', line 67

def run
  system final_command
end

#screenshot_nameObject



59
60
61
# File 'lib/cejo/ops/screenshot.rb', line 59

def screenshot_name
  "screenshot-#{CURRENT_TIME}.#{SCREENSHOT_FORMAT}"
end

#scrotObject



32
33
34
35
36
37
38
39
# File 'lib/cejo/ops/screenshot.rb', line 32

def scrot
  {
    bin: 'scrot',
    full: '--focused --silent',
    partial: '--select --silent',
    folder: FOLDER.join(screenshot_name)
  }
end

#shotterObject



28
29
30
# File 'lib/cejo/ops/screenshot.rb', line 28

def shotter
  shotters_available.first
end

#shottersObject



18
19
20
# File 'lib/cejo/ops/screenshot.rb', line 18

def shotters
  [flameshot, scrot, maim]
end

#shotters_availableObject



22
23
24
25
26
# File 'lib/cejo/ops/screenshot.rb', line 22

def shotters_available
  shotters.find_all do |shotter|
    shotter[:bin] if utils.which? shotter[:bin]
  end
end