Class: Pagelapse::Recorder
- Inherits:
-
Object
- Object
- Pagelapse::Recorder
- Defined in:
- lib/pagelapse/recorder.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#height ⇒ Object
Returns the value of attribute height.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #before_capture(&block) ⇒ Object
- #capture ⇒ Object
- #capture_if(&block) ⇒ Object
-
#expired? ⇒ Boolean
Returns true if recorder has expired.
- #filename ⇒ Object
-
#initialize(name, url) ⇒ Recorder
constructor
A new instance of Recorder.
-
#ready? ⇒ Boolean
Returns true if timer is expired and ready to capture.
- #save_if(&block) ⇒ Object
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
#duration ⇒ Object
Returns the value of attribute duration.
4 5 6 |
# File 'lib/pagelapse/recorder.rb', line 4 def duration @duration end |
#expiration ⇒ Object
Returns the value of attribute expiration.
4 5 6 |
# File 'lib/pagelapse/recorder.rb', line 4 def expiration @expiration end |
#height ⇒ Object
Returns the value of attribute height.
4 5 6 |
# File 'lib/pagelapse/recorder.rb', line 4 def height @height end |
#interval ⇒ Object
Returns the value of attribute interval.
4 5 6 |
# File 'lib/pagelapse/recorder.rb', line 4 def interval @interval end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/pagelapse/recorder.rb', line 5 def name @name end |
#timeout ⇒ Object
Returns the value of attribute timeout.
4 5 6 |
# File 'lib/pagelapse/recorder.rb', line 4 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/pagelapse/recorder.rb', line 5 def url @url end |
#width ⇒ Object
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 |
#capture ⇒ Object
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
45 46 47 |
# File 'lib/pagelapse/recorder.rb', line 45 def expired? Time.now > @start + @expiration if @expiration end |
#filename ⇒ Object
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
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 |