Sha256: 86726ee7832ad696f325a0b7085660074edbadf0508110cad153b5ade6a7b287

Contents?: true

Size: 1.83 KB

Versions: 60

Compression:

Stored size: 1.83 KB

Contents

require 'spaceship/connect_api/models/app_screenshot'
require 'spaceship/connect_api/models/app_screenshot_set'

require_relative 'app_screenshot'

module Deliver
  # 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`.
  class ScreenshotComparable
    # A unique key value that is consist of locale, filename, and checksum.
    attr_reader :key

    # A hash object that contains the source data of this representation class
    attr_reader :context

    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

    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

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

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

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

    def hash
      key.hash
    end
  end
end

Version data entries

60 entries across 60 versions & 4 rubygems

Version Path
fastlane-2.226.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.225.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.224.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.223.1 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.223.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.222.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.221.1 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.221.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.220.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.219.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.218.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-security-patched-2.216.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.217.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.216.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.215.1 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.215.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-mercafacil-2.214.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.214.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.213.0 deliver/lib/deliver/screenshot_comparable.rb
fastlane-2.212.2 deliver/lib/deliver/screenshot_comparable.rb