Class: Deliver::ScreenshotComparable

Inherits:
Object
  • Object
show all
Defined in:
deliver/lib/deliver/screenshot_comparable.rb

Overview

This clsas enables you to compare equality between different representations of the screenshots in the standard API ‘Array#-` that requires objects to implements `eql?` and `hash`.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, checksum:, context:) ⇒ ScreenshotComparable

Returns a new instance of ScreenshotComparable.



49
50
51
52
# File 'deliver/lib/deliver/screenshot_comparable.rb', line 49

def initialize(path:, checksum:, context:)
  @key = "#{path}/#{checksum}"
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

A hash object that contains the source data of this representation class



14
15
16
# File 'deliver/lib/deliver/screenshot_comparable.rb', line 14

def context
  @context
end

#keyObject (readonly)

A unique key value that is consist of locale, filename, and checksum.



11
12
13
# File 'deliver/lib/deliver/screenshot_comparable.rb', line 11

def key
  @key
end

Class Method Details

.calculate_checksum(path) ⇒ Object



44
45
46
47
# File 'deliver/lib/deliver/screenshot_comparable.rb', line 44

def self.calculate_checksum(path)
  bytes = File.binread(path)
  Digest::MD5.hexdigest(bytes)
end

.create_from_local(screenshot:, app_screenshot_set:) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'deliver/lib/deliver/screenshot_comparable.rb', line 16

def self.create_from_local(screenshot:, app_screenshot_set:)
  raise ArgumentError unless screenshot.kind_of?(Deliver::AppScreenshot)
  raise ArgumentError unless app_screenshot_set.kind_of?(Spaceship::ConnectAPI::AppScreenshotSet)

  new(
    path: "#{screenshot.language}/#{File.basename(screenshot.path)}",
    checksum: calculate_checksum(screenshot.path),
    context: {
      screenshot: screenshot,
      app_screenshot_set: app_screenshot_set
    }
  )
end

.create_from_remote(app_screenshot:, locale:) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'deliver/lib/deliver/screenshot_comparable.rb', line 30

def self.create_from_remote(app_screenshot:, locale:)
  raise ArgumentError unless app_screenshot.kind_of?(Spaceship::ConnectAPI::AppScreenshot)
  raise ArgumentError unless locale.kind_of?(String)

  new(
    path: "#{locale}/#{app_screenshot.file_name}",
    checksum: app_screenshot.source_file_checksum,
    context: {
      app_screenshot: app_screenshot,
      locale: locale
    }
  )
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:



54
55
56
# File 'deliver/lib/deliver/screenshot_comparable.rb', line 54

def eql?(other)
  key == other.key
end

#hashObject



58
59
60
# File 'deliver/lib/deliver/screenshot_comparable.rb', line 58

def hash
  key.hash
end