Class: Applitools::Screenshot

Inherits:
Delegator
  • Object
show all
Defined in:
lib/applitools/core/screenshot.rb

Direct Known Subclasses

Datastream, Image

Defined Under Namespace

Classes: Datastream, Image

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_image) ⇒ Screenshot

Returns a new instance of Screenshot.



26
27
28
# File 'lib/applitools/core/screenshot.rb', line 26

def initialize(_image)
  raise Applitools::EyesError.new 'Applitools::Screenshot is an abstract class!'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/applitools/core/screenshot.rb', line 34

def method_missing(method, *args, &block)
  if method =~ /^.+!$/
    __setobj__ super
  else
    super
  end
end

Class Method Details

.from_any_image(image) ⇒ Object



18
19
20
21
22
23
# File 'lib/applitools/core/screenshot.rb', line 18

def from_any_image(image)
  return from_region(image) if image.is_a? Applitools::Region
  return from_image(image) if image.is_a? ::ChunkyPNG::Image
  return image if image.is_a?(Image) | image.is_a?(Datastream)
  from_datastream(image)
end

.from_datastream(datastream) ⇒ Object



10
11
12
# File 'lib/applitools/core/screenshot.rb', line 10

def from_datastream(datastream)
  self::Datastream.new(datastream)
end

.from_image(image) ⇒ Object



14
15
16
# File 'lib/applitools/core/screenshot.rb', line 14

def from_image(image)
  Image.new(image)
end

.from_region(region) ⇒ Object



6
7
8
# File 'lib/applitools/core/screenshot.rb', line 6

def from_region(region)
  self::Image.new(::ChunkyPNG::Image.new(region.width, region.height))
end

Instance Method Details

#__getobj__Object



30
31
32
# File 'lib/applitools/core/screenshot.rb', line 30

def __getobj__
  nil
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/applitools/core/screenshot.rb', line 42

def respond_to_missing?(method_name, include_private = false)
  super
end

#squareObject



46
47
48
# File 'lib/applitools/core/screenshot.rb', line 46

def square
  width * height
end