Class: Pagelapse::Recorder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url) ⇒ Recorder

Returns a new instance of Recorder.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pagelapse/recorder.rb', line 7

def initialize(name, url)
  @name = name
  @url = url
  @interval = 20
  @duration = nil
  @on_load = nil
  @expiration = nil
  @start = Time.now
  @width = 1240
  @height = 900
  @timer = Time.new 0
  @capture_if = nil
  @save_if = nil
  FileUtils.mkdir_p(File.join 'lapses', @name)
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



4
5
6
# File 'lib/pagelapse/recorder.rb', line 4

def duration
  @duration
end

#expirationObject

Returns the value of attribute expiration.



4
5
6
# File 'lib/pagelapse/recorder.rb', line 4

def expiration
  @expiration
end

#heightObject

Returns the value of attribute height.



4
5
6
# File 'lib/pagelapse/recorder.rb', line 4

def height
  @height
end

#intervalObject

Returns the value of attribute interval.



4
5
6
# File 'lib/pagelapse/recorder.rb', line 4

def interval
  @interval
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/pagelapse/recorder.rb', line 5

def name
  @name
end

#timeoutObject

Returns the value of attribute timeout.



4
5
6
# File 'lib/pagelapse/recorder.rb', line 4

def timeout
  @timeout
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/pagelapse/recorder.rb', line 5

def url
  @url
end

#widthObject

Returns the value of attribute width.



4
5
6
# File 'lib/pagelapse/recorder.rb', line 4

def width
  @width
end

Instance Method Details

#before_capture(&block) ⇒ Object



23
24
25
# File 'lib/pagelapse/recorder.rb', line 23

def before_capture(&block)
  @on_load = block
end

#captureObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pagelapse/recorder.rb', line 49

def capture
  @timer = Time.now
  ws = Pagelapse::Screenshot.new

  ws.capture(
    @url,
    filename,
    width: @width,
    height: @height,
    timeout: @timeout,
    capture_if: @capture_if,
    save_if: @save_if,
    on_load: @on_load
  )
end

#capture_if(&block) ⇒ Object



27
28
29
# File 'lib/pagelapse/recorder.rb', line 27

def capture_if(&block)
  @capture_if = block
end

#expired?Boolean

Returns true if recorder has expired

Returns:

  • (Boolean)


45
46
47
# File 'lib/pagelapse/recorder.rb', line 45

def expired?
  Time.now > @start + @expiration if @expiration
end

#filenameObject



35
36
37
# File 'lib/pagelapse/recorder.rb', line 35

def filename
  File.join 'lapses', @name, "#{Time.now.to_i}.png"
end

#ready?Boolean

Returns true if timer is expired and ready to capture

Returns:

  • (Boolean)


40
41
42
# File 'lib/pagelapse/recorder.rb', line 40

def ready?
  @timer < Time.now - @interval
end

#save_if(&block) ⇒ Object



31
32
33
# File 'lib/pagelapse/recorder.rb', line 31

def save_if(&block)
  @save_if = block
end