Class: Deliver::AppScreenshot

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

Overview

AppScreenshot represents one screenshots for one specific locale and device type.

Defined Under Namespace

Modules: ScreenSize

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, language, screen_size = nil) ⇒ AppScreenshot

Returns a new instance of AppScreenshot.

Parameters:

  • path (String)

    path to the screenshot file

  • language (String)

    Language of this screenshot (e.g. English)

  • screen_size (Deliver::AppScreenshot::ScreenSize) (defaults to: nil)

    the screen size, which will automatically be calculated when you don't set it.


86
87
88
89
90
91
92
93
94
# File 'deliver/lib/deliver/app_screenshot.rb', line 86

def initialize(path, language, screen_size = nil)
  self.path = path
  self.language = language
  screen_size ||= self.class.calculate_screen_size(path)

  self.screen_size = screen_size

  UI.error("Looks like the screenshot given (#{path}) does not match the requirements of #{screen_size}") unless self.is_valid?
end

Instance Attribute Details

#languageObject

Returns the value of attribute language


80
81
82
# File 'deliver/lib/deliver/app_screenshot.rb', line 80

def language
  @language
end

#pathObject

Returns the value of attribute path


78
79
80
# File 'deliver/lib/deliver/app_screenshot.rb', line 78

def path
  @path
end

#screen_sizeDeliver::ScreenSize

Returns the screen size (device type) specified at ScreenSize.

Returns:


76
77
78
# File 'deliver/lib/deliver/app_screenshot.rb', line 76

def screen_size
  @screen_size
end

Class Method Details

.calculate_screen_size(path) ⇒ Object


333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'deliver/lib/deliver/app_screenshot.rb', line 333

def self.calculate_screen_size(path)
  size = FastImage.size(path)

  UI.user_error!("Could not find or parse file at path '#{path}'") if size.nil? || size.count == 0

  # iMessage screenshots have same resolution as app screenshots so we need to distinguish them
  path_component = Pathname.new(path).each_filename.to_a[-3]
  devices = path_component.eql?("iMessage") ? self.device_messages : self.devices

  devices.each do |screen_size, resolutions|
    if resolutions.include?(size)
      filename = Pathname.new(path).basename.to_s
      return resolve_ipadpro_conflict_if_needed(screen_size, filename)
    end
  end

  UI.user_error!("Unsupported screen size #{size} for path '#{path}'")
end

.device_messagesObject


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'deliver/lib/deliver/app_screenshot.rb', line 184

def self.device_messages
  # This list does not include iPad Pro 12.9-inch (3rd generation)
  # because it has same resoluation as IOS_IPAD_PRO and will clobber
  return {
    ScreenSize::IOS_65_MESSAGES => [
      [1242, 2688],
      [2688, 1242]
    ],
    ScreenSize::IOS_61_MESSAGES => [
      [828, 1792],
      [1792, 828]
    ],
    ScreenSize::IOS_58_MESSAGES => [
      [1125, 2436],
      [2436, 1125]
    ],
    ScreenSize::IOS_55_MESSAGES => [
      [1242, 2208],
      [2208, 1242]
    ],
    ScreenSize::IOS_47_MESSAGES => [
      [750, 1334],
      [1334, 750]
    ],
    ScreenSize::IOS_40_MESSAGES => [
      [640, 1096],
      [640, 1136],
      [1136, 600],
      [1136, 640]
    ],
    ScreenSize::IOS_IPAD_MESSAGES => [
      [1024, 748],
      [1024, 768],
      [2048, 1496],
      [2048, 1536],
      [768, 1004],
      [768, 1024],
      [1536, 2008],
      [1536, 2048]
    ],
    ScreenSize::IOS_IPAD_10_5_MESSAGES => [
      [1668, 2224],
      [2224, 1668]
    ],
    ScreenSize::IOS_IPAD_11_MESSAGES => [
      [1668, 2388],
      [2388, 1668]
    ],
    ScreenSize::IOS_IPAD_PRO_MESSAGES => [
      [2732, 2048],
      [2048, 2732]
    ]
  }
end

.devicesObject


240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'deliver/lib/deliver/app_screenshot.rb', line 240

def self.devices
  # This list does not include iPad Pro 12.9-inch (3rd generation)
  # because it has same resoluation as IOS_IPAD_PRO and will clobber
  return {
    ScreenSize::IOS_65 => [
      [1242, 2688],
      [2688, 1242]
    ],
    ScreenSize::IOS_61 => [
      [828, 1792],
      [1792, 828]
    ],
    ScreenSize::IOS_58 => [
      [1125, 2436],
      [2436, 1125]
    ],
    ScreenSize::IOS_55 => [
      [1242, 2208],
      [2208, 1242]
    ],
    ScreenSize::IOS_47 => [
      [750, 1334],
      [1334, 750]
    ],
    ScreenSize::IOS_40 => [
      [640, 1096],
      [640, 1136],
      [1136, 600],
      [1136, 640]
    ],
    ScreenSize::IOS_35 => [
      [640, 920],
      [640, 960],
      [960, 600],
      [960, 640]
    ],
    ScreenSize::IOS_IPAD => [ # 9.7 inch
      [1024, 748],
      [1024, 768],
      [2048, 1496],
      [2048, 1536],
      [768, 1004], # portrait without status bar
      [768, 1024],
      [1536, 2008], # portrait without status bar
      [1536, 2048]
    ],
    ScreenSize::IOS_IPAD_10_5 => [
      [1668, 2224],
      [2224, 1668]
    ],
    ScreenSize::IOS_IPAD_11 => [
      [1668, 2388],
      [2388, 1668]
    ],
    ScreenSize::IOS_IPAD_PRO => [
      [2732, 2048],
      [2048, 2732]
    ],
    ScreenSize::MAC => [
      [1280, 800],
      [1440, 900],
      [2560, 1600],
      [2880, 1800]
    ],
    ScreenSize::IOS_APPLE_WATCH => [
      [312, 390]
    ],
    ScreenSize::IOS_APPLE_WATCH_SERIES4 => [
      [368, 448]
    ],
    ScreenSize::APPLE_TV => [
      [1920, 1080],
      [3840, 2160]
    ]
  }
end

.resolve_ipadpro_conflict_if_needed(screen_size, filename) ⇒ Object


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'deliver/lib/deliver/app_screenshot.rb', line 317

def self.resolve_ipadpro_conflict_if_needed(screen_size, filename)
  is_3rd_gen = [
    "iPad Pro (12.9-inch) (3rd generation)", # default simulator name has this
    "iPad Pro (12.9-inch) (4th generation)", # default simulator name has this
    "ipadPro129" # downloaded screenshots name has this
  ].any? { |key| filename.include?(key) }
  if is_3rd_gen
    if screen_size == ScreenSize::IOS_IPAD_PRO
      return ScreenSize::IOS_IPAD_PRO_12_9
    elsif screen_size == ScreenSize::IOS_IPAD_PRO_MESSAGES
      return ScreenSize::IOS_IPAD_PRO_12_9_MESSAGES
    end
  end
  screen_size
end

Instance Method Details

#device_typeObject

The iTC API requires a different notation for the device


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'deliver/lib/deliver/app_screenshot.rb', line 97

def device_type
  matching = {
    ScreenSize::IOS_35 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPHONE_35,
    ScreenSize::IOS_40 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPHONE_40,
    ScreenSize::IOS_47 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPHONE_47, # also 7 & 8
    ScreenSize::IOS_55 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPHONE_55, # also 7 Plus & 8 Plus
    ScreenSize::IOS_58 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPHONE_58,
    ScreenSize::IOS_65 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPHONE_65,
    ScreenSize::IOS_IPAD => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPAD_97,
    ScreenSize::IOS_IPAD_10_5 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPAD_105,
    ScreenSize::IOS_IPAD_11 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPAD_PRO_3GEN_11,
    ScreenSize::IOS_IPAD_PRO => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPAD_PRO_129,
    ScreenSize::IOS_IPAD_PRO_12_9 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPAD_PRO_3GEN_129,
    ScreenSize::IOS_40_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::IMESSAGE_APP_IPHONE_40,
    ScreenSize::IOS_47_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::IMESSAGE_APP_IPHONE_47, # also 7 & 8
    ScreenSize::IOS_55_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::IMESSAGE_APP_IPHONE_55, # also 7 Plus & 8 Plus
    ScreenSize::IOS_58_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::IMESSAGE_APP_IPHONE_58,
    ScreenSize::IOS_65_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::IMESSAGE_APP_IPHONE_65,
    ScreenSize::IOS_IPAD_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::IMESSAGE_APP_IPAD_97,
    ScreenSize::IOS_IPAD_PRO_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPAD_PRO_129,
    ScreenSize::IOS_IPAD_PRO_12_9_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_IPAD_PRO_3GEN_129,
    ScreenSize::IOS_IPAD_10_5_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::IMESSAGE_APP_IPAD_105,
    ScreenSize::IOS_IPAD_11_MESSAGES => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::IMESSAGE_APP_IPAD_PRO_3GEN_11,
    ScreenSize::MAC => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_DESKTOP,
    ScreenSize::IOS_APPLE_WATCH => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_WATCH_SERIES_3,
    ScreenSize::IOS_APPLE_WATCH_SERIES4 => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::APP_WATCH_SERIES_4,
    # ScreenSize::APPLE_TV => Spaceship::ConnectAPI::AppScreenshotSet::DisplayType::
  }
  return matching[self.screen_size]
end

#formatted_nameObject

Nice name


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'deliver/lib/deliver/app_screenshot.rb', line 129

def formatted_name
  matching = {
    ScreenSize::IOS_35 => "iPhone 4",
    ScreenSize::IOS_40 => "iPhone 5",
    ScreenSize::IOS_47 => "iPhone 6", # also 7 & 8
    ScreenSize::IOS_55 => "iPhone 6 Plus", # also 7 Plus & 8 Plus
    ScreenSize::IOS_58 => "iPhone XS",
    ScreenSize::IOS_61 => "iPhone XR",
    ScreenSize::IOS_65 => "iPhone XS Max",
    ScreenSize::IOS_IPAD => "iPad",
    ScreenSize::IOS_IPAD_10_5 => "iPad 10.5",
    ScreenSize::IOS_IPAD_11 => "iPad 11",
    ScreenSize::IOS_IPAD_PRO => "iPad Pro",
    ScreenSize::IOS_IPAD_PRO_12_9 => "iPad Pro (12.9-inch) (3rd generation)",
    ScreenSize::IOS_40_MESSAGES => "iPhone 5 (iMessage)",
    ScreenSize::IOS_47_MESSAGES => "iPhone 6 (iMessage)", # also 7 & 8
    ScreenSize::IOS_55_MESSAGES => "iPhone 6 Plus (iMessage)", # also 7 Plus & 8 Plus
    ScreenSize::IOS_58_MESSAGES => "iPhone XS (iMessage)",
    ScreenSize::IOS_61_MESSAGES => "iPhone XR (iMessage)",
    ScreenSize::IOS_65_MESSAGES => "iPhone XS Max (iMessage)",
    ScreenSize::IOS_IPAD_MESSAGES => "iPad (iMessage)",
    ScreenSize::IOS_IPAD_PRO_MESSAGES => "iPad Pro (iMessage)",
    ScreenSize::IOS_IPAD_PRO_12_9_MESSAGES => "iPad Pro (12.9-inch) (3rd generation) (iMessage)",
    ScreenSize::IOS_IPAD_10_5_MESSAGES => "iPad 10.5 (iMessage)",
    ScreenSize::IOS_IPAD_11_MESSAGES => "iPad 11 (iMessage)",
    ScreenSize::MAC => "Mac",
    ScreenSize::IOS_APPLE_WATCH => "Watch",
    ScreenSize::IOS_APPLE_WATCH_SERIES4 => "Watch Series4",
    ScreenSize::APPLE_TV => "Apple TV"
  }
  return matching[self.screen_size]
end

#is_messages?Boolean

Returns:

  • (Boolean)

169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'deliver/lib/deliver/app_screenshot.rb', line 169

def is_messages?
  return [
    ScreenSize::IOS_40_MESSAGES,
    ScreenSize::IOS_47_MESSAGES,
    ScreenSize::IOS_55_MESSAGES,
    ScreenSize::IOS_58_MESSAGES,
    ScreenSize::IOS_65_MESSAGES,
    ScreenSize::IOS_IPAD_MESSAGES,
    ScreenSize::IOS_IPAD_PRO_MESSAGES,
    ScreenSize::IOS_IPAD_PRO_12_9_MESSAGES,
    ScreenSize::IOS_IPAD_10_5_MESSAGES,
    ScreenSize::IOS_IPAD_11_MESSAGES
  ].include?(self.screen_size)
end

#is_valid?Boolean

Validates the given screenshots (size and format)

Returns:

  • (Boolean)

163
164
165
166
167
# File 'deliver/lib/deliver/app_screenshot.rb', line 163

def is_valid?
  return false unless ["png", "PNG", "jpg", "JPG", "jpeg", "JPEG"].include?(self.path.split(".").last)

  return self.screen_size == self.class.calculate_screen_size(self.path)
end