Class: Snapit::Engine

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage, width) ⇒ Engine

Returns a new instance of Engine.



8
9
10
11
# File 'lib/snapit/engine.rb', line 8

def initialize(storage, width)
  @storage = storage
  @width = width
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



5
6
7
# File 'lib/snapit/engine.rb', line 5

def storage
  @storage
end

#widthObject (readonly)

Returns the value of attribute width.



6
7
8
# File 'lib/snapit/engine.rb', line 6

def width
  @width
end

Class Method Details

.run(storage, width = 1280) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/snapit/engine.rb', line 13

def self.run(storage, width = 1280)
  begin
    engine = new(storage, width)
    yield engine
  ensure
    engine.stop!
  end
end

Instance Method Details

#capture!(url, name_or_idx) ⇒ Object



26
27
28
29
# File 'lib/snapit/engine.rb', line 26

def capture!(url, name_or_idx)
  driver.get(url)
  driver.save_screenshot("#{storage.output_path.join(name_or_idx)}.png")
end

#output_pathObject



22
23
24
# File 'lib/snapit/engine.rb', line 22

def output_path
  
end

#stop!Object



31
32
33
# File 'lib/snapit/engine.rb', line 31

def stop!
  driver.quit
end