isa 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/isa/session.rb +92 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2dd9cec4133a47fe5de7f2984c395bf243c1dda
|
4
|
+
data.tar.gz: 77dfaac88e20c4dc3e1fb6a2b0b6bc59929cd863
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66294a07f2763f98e26564526784c5e53743bba47ade3f84358fb1006a0ee895ae6c852e5bc110e35dcbfd51198dece63fa92b19b9665bfd7fc259b7f8401f05
|
7
|
+
data.tar.gz: 037fbe778cab6a129cdff77ae8beee24f6b6815283792567dc164b367e4c33e5075ed4604f71a3ce1594908188550c581ad1f21d5ca14b71d08907b70d0ac1c3
|
data/lib/isa/session.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module ISA
|
5
|
+
|
6
|
+
# Main class for managing the capture sessions
|
7
|
+
class Session
|
8
|
+
|
9
|
+
attr_accessor :name, :tmp_dir, :dir, :code, :images, :checkpoint, :last_capture
|
10
|
+
|
11
|
+
# Initialize a capture session
|
12
|
+
# Takes a number of args:
|
13
|
+
# * session (optional) -- name for the capture session
|
14
|
+
# * dir (optional) -- directory to save the screenshots
|
15
|
+
# * capture (required) -- lambda for performing a screenshot
|
16
|
+
# The lambda should take a single argument filename:
|
17
|
+
# take_screenshot = ->(filename) {
|
18
|
+
# code_to_perform_screenshot( :save_to => filename )
|
19
|
+
# }
|
20
|
+
def initialize( args )
|
21
|
+
@name = args[:session] || Time.now.to_i
|
22
|
+
@code = args[:capture] or raise 'Need to provide a lambda to the constructor'
|
23
|
+
@tmp_dir = "/tmp/isa/#{@name}"
|
24
|
+
@dir = args[:dir] || @tmp_dir
|
25
|
+
|
26
|
+
FileUtils.mkdir_p(@dir)
|
27
|
+
FileUtils.mkdir_p(@tmp_dir)
|
28
|
+
|
29
|
+
File.directory?(@dir) or raise "Couldn't create session directory for screen grabs"
|
30
|
+
|
31
|
+
@images = Magick::ImageList.new
|
32
|
+
end
|
33
|
+
|
34
|
+
# Perform a screenshot capture
|
35
|
+
def capture(checkpoint = nil)
|
36
|
+
|
37
|
+
if checkpoint
|
38
|
+
@checkpoint = checkpoint
|
39
|
+
end
|
40
|
+
|
41
|
+
filename = (@checkpoint ? @checkpoint.to_s + '-' : '') + Time.now.to_i.to_s + '.png'
|
42
|
+
|
43
|
+
file = "#{tmp_dir}/#{filename}"
|
44
|
+
|
45
|
+
capture_time = Time.now
|
46
|
+
code.call(file)
|
47
|
+
|
48
|
+
File.exist? file or raise "Couldn't capture screenshot"
|
49
|
+
|
50
|
+
image = Magick::ImageList.new(file).first
|
51
|
+
|
52
|
+
if @last_capture
|
53
|
+
delay = (capture_time - @last_capture).to_i
|
54
|
+
images.last.delay = delay
|
55
|
+
end
|
56
|
+
@last_capture = capture_time
|
57
|
+
|
58
|
+
images << image
|
59
|
+
image
|
60
|
+
end
|
61
|
+
|
62
|
+
# Performs a capture and diffs it with the last image
|
63
|
+
def diff
|
64
|
+
if images.count == 0
|
65
|
+
self.capture
|
66
|
+
end
|
67
|
+
|
68
|
+
last = images.last
|
69
|
+
current = self.capture
|
70
|
+
|
71
|
+
last.difference(current)[0].to_i
|
72
|
+
end
|
73
|
+
|
74
|
+
# Finalize the capture session, and create an animated gif
|
75
|
+
# of the capture session
|
76
|
+
def end(filename = nil)
|
77
|
+
if !filename
|
78
|
+
filename = "#{@dir}/#{@name}.gif"
|
79
|
+
else
|
80
|
+
filename = "#{@dir}/#{@filename}"
|
81
|
+
end
|
82
|
+
images.ticks_per_second = 2
|
83
|
+
puts "Writing to #{filename}"
|
84
|
+
width = 750
|
85
|
+
height = 750
|
86
|
+
images.each {|i| i.resize_to_fit!(width, height) }
|
87
|
+
images.write(filename)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: isa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Buckhurst
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Analysis tool for investigating screenshots taken over a session
|
28
|
+
email: david.buckhurst@bbc.co.uk
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/isa/session.rb
|
34
|
+
homepage: https://github.com/bbc-test/isa
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.2.2
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Image Session Analyzer
|
58
|
+
test_files: []
|