Class: Applitools::Screenshot::Datastream

Inherits:
Applitools::Screenshot show all
Extended by:
Forwardable
Defined in:
lib/applitools/core/screenshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Applitools::Screenshot

from_any_image, from_datastream, from_image, from_region, #method_missing, #respond_to_missing?, #square

Constructor Details

#initialize(image) ⇒ Datastream

Returns a new instance of Datastream.



56
57
58
59
60
61
62
63
64
# File 'lib/applitools/core/screenshot.rb', line 56

def initialize(image)
  Applitools::ArgumentGuard.not_nil(image, 'image')
  unless image.is_a?(String)
    Applitools::ArgumentGuard.raise_argument_error(
      "Expected image to be Datastream or String, but got #{image.class}"
    )
  end
  # @datastream = ::ChunkyPNG::Datastream.from_string image
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Applitools::Screenshot

Instance Attribute Details

#datastreamObject (readonly)

Returns the value of attribute datastream.



54
55
56
# File 'lib/applitools/core/screenshot.rb', line 54

def datastream
  @datastream
end

Instance Method Details

#__getobj__Object Also known as: image



81
82
83
# File 'lib/applitools/core/screenshot.rb', line 81

def __getobj__
  restore
end

#__setobj__(obj) ⇒ Object



87
88
89
90
# File 'lib/applitools/core/screenshot.rb', line 87

def __setobj__(obj)
  @datastream = obj.to_datastream
  self
end

#headerObject



77
78
79
# File 'lib/applitools/core/screenshot.rb', line 77

def header
  @datastream.header_chunk
end

#restoreObject



92
93
94
# File 'lib/applitools/core/screenshot.rb', line 92

def restore
  # ::ChunkyPNG::Image.from_datastream @datastream
end

#sha256Object



96
97
98
# File 'lib/applitools/core/screenshot.rb', line 96

def sha256
  Digest::SHA2.new(256).hexdigest(@datastream.to_s)
end

#to_blobObject



73
74
75
# File 'lib/applitools/core/screenshot.rb', line 73

def to_blob
  @datastream.to_blob
end

#update!(image) ⇒ Object



66
67
68
69
70
71
# File 'lib/applitools/core/screenshot.rb', line 66

def update!(image)
  Applitools::ArgumentGuard.not_nil(image, 'image')
  # Applitools::ArgumentGuard.is_a?(image, 'image', ::ChunkyPNG::Image)
  @datastream = image.to_datastream
  self
end