Class: X4ss

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

Instance Method Summary collapse

Constructor Details

#initialize(savefile = nil, mouse: false, window: false, debug: false) ⇒ X4ss

Returns a new instance of X4ss.



14
15
16
17
18
19
20
21
22
23
# File 'lib/x4ss.rb', line 14

def initialize(savefile=nil, mouse: false, window: false, debug: false)

  @file = savefile
  @count = 1
  @mouse = mouse ? 'm' : ''
  @blob = []
  @mode = window ? :window : :fullscreen
  @debug = debug

end

Instance Method Details

#capture(mode = @mode) ⇒ Object

mode options: :window, :fullscreen



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/x4ss.rb', line 27

def capture(mode=@mode)
  
  blob = screenshot(mode)
  
  if @file then
  
    File.write @file % @count, blob
    
  end

  @count += 1    
  @blob << blob

end

#from_blobObject



42
43
44
# File 'lib/x4ss.rb', line 42

def from_blob
  @blob
end

#record(interval: 1, duration: 6, mode: @mode) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/x4ss.rb', line 46

def record(interval: 1, duration: 6, mode: @mode)
  
  return 'interval must be 0.8 or greater' if interval < 0.8

  t = Time.now

  while(Time.now <= t+duration) do

    puts 'time: ' + Time.now.inspect
    @blob << screenshot(mode)
    sleep interval
    yield(@blob.shift) if block_given?

  end

end

#save(file = @file) ⇒ Object



63
64
65
66
67
68
# File 'lib/x4ss.rb', line 63

def save(file=@file)
  
  @blob.each.with_index {|blob, i| File.write file % (i+1).to_s, blob }
      
  :saved
end