Class: DotDiff::Snapshot

Inherits:
Object
  • Object
show all
Includes:
Image::Cropper
Defined in:
lib/dotdiff/snapshot.rb

Constant Summary collapse

IMAGE_EXT =
'png'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Image::Cropper

#crop_and_resave, #height, #load_image, #width

Constructor Details

#initialize(options = {}) ⇒ Snapshot

Returns a new instance of Snapshot.



9
10
11
12
13
14
15
# File 'lib/dotdiff/snapshot.rb', line 9

def initialize(options = {})
  opts = { rootdir: DotDiff.image_store_path }.merge(Hash(options))
  @base_filename = opts[:filename]
  @subdir = opts[:subdir].to_s
  @rootdir = opts[:rootdir].to_s
  @page = opts[:page]
end

Instance Attribute Details

#base_filename(with_extention = true) ⇒ Object (readonly)

Returns the value of attribute base_filename.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def base_filename
  @base_filename
end

#pageObject (readonly)

Returns the value of attribute page.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def page
  @page
end

#rootdirObject (readonly)

Returns the value of attribute rootdir.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def rootdir
  @rootdir
end

#subdirObject (readonly)

Returns the value of attribute subdir.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def subdir
  @subdir
end

Instance Method Details

#basefileObject



25
26
27
# File 'lib/dotdiff/snapshot.rb', line 25

def basefile
  File.join(rootdir, subdir.to_s, base_filename)
end

#capture_from_browser(hide_and_show = true, element_handler = ElementHandler.new(page)) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/dotdiff/snapshot.rb', line 43

def capture_from_browser(hide_and_show = true, element_handler = ElementHandler.new(page))
  if hide_and_show
    element_handler.hide
    page.save_screenshot(fullscreen_file)
    element_handler.show
  else
    page.save_screenshot(fullscreen_file)
  end
end

#cropped_fileObject



21
22
23
# File 'lib/dotdiff/snapshot.rb', line 21

def cropped_file
  @cropped ||= File.join(Dir.tmpdir, subdir, "#{base_filename(false)}_cropped.#{IMAGE_EXT}")
end

#fullscreen_fileObject



17
18
19
# File 'lib/dotdiff/snapshot.rb', line 17

def fullscreen_file
  @fullscreen ||= File.join(Dir.tmpdir, subdir, base_filename)
end

#resave_cropped_fileObject



53
54
55
# File 'lib/dotdiff/snapshot.rb', line 53

def resave_cropped_file
  resave_base_file(:cropped)
end

#resave_fullscreen_fileObject



57
58
59
# File 'lib/dotdiff/snapshot.rb', line 57

def resave_fullscreen_file
  resave_base_file(:fullscreen)
end