lib/deliver/app_screenshot.rb in deliver-1.6.6 vs lib/deliver/app_screenshot.rb in deliver-1.7.0

- old
+ new

@@ -19,10 +19,12 @@ IOS_IPAD_PRO = "iOS-iPad-Pro" # Apple Watch IOS_APPLE_WATCH = "iOS-Apple-Watch" # Mac MAC = "Mac" + # Apple TV + APPLE_TV = "Apple-TV" end # @return [Deliver::ScreenSize] the screen size (device type) # specified at {Deliver::ScreenSize} attr_accessor :screen_size @@ -53,11 +55,12 @@ ScreenSize::IOS_47 => "iphone6", ScreenSize::IOS_55 => "iphone6Plus", ScreenSize::IOS_IPAD => "ipad", ScreenSize::IOS_IPAD_PRO => "ipadPro", ScreenSize::MAC => "desktop", - ScreenSize::IOS_APPLE_WATCH => "watch" + ScreenSize::IOS_APPLE_WATCH => "watch", + ScreenSize::APPLE_TV => "appleTV" } return matching[self.screen_size] end # Nice name @@ -68,11 +71,12 @@ ScreenSize::IOS_47 => "iPhone 6", ScreenSize::IOS_55 => "iPhone 6 Plus", ScreenSize::IOS_IPAD => "iPad", ScreenSize::IOS_IPAD_PRO => "iPad Pro", ScreenSize::MAC => "Mac", - ScreenSize::IOS_APPLE_WATCH => "Watch" + ScreenSize::IOS_APPLE_WATCH => "Watch", + ScreenSize::APPLE_TV => "Apple TV" } return matching[self.screen_size] end # Validates the given screenshots (size and format) @@ -82,16 +86,12 @@ return self.screen_size == self.class.calculate_screen_size(self.path) end # rubocop:enable Style/PredicateName - def self.calculate_screen_size(path) - size = FastImage.size(path) - - raise "Could not find or parse file at path '#{path}'" if size.nil? or size.count == 0 - - devices = { + def self.devices + return { ScreenSize::IOS_55 => [ [1080, 1920], [1242, 2208] ], ScreenSize::IOS_47 => [ @@ -127,17 +127,38 @@ [2880, 1800], [2560, 1600] ], ScreenSize::IOS_APPLE_WATCH => [ [312, 390] + ], + ScreenSize::APPLE_TV => [ + [1920, 1080] ] } + end - devices.each do |device_type, array| + def self.calculate_screen_size(path) + size = FastImage.size(path) + + raise "Could not find or parse file at path '#{path}'" if size.nil? or size.count == 0 + + # Walk up two directories and test if we need to handle a platform that doesn't support landscape + path_component = Pathname.new(path).each_filename.to_a[-3] + if path_component.eql? "appleTV" + skip_landscape = true + end + + self.devices.each do |device_type, array| array.each do |resolution| - if (size[0] == resolution[0] and size[1] == resolution[1]) or # portrait - (size[1] == resolution[0] and size[0] == resolution[1]) # landscape - return device_type + if skip_landscape + if size[0] == resolution[0] and size[1] == resolution[1] # portrait + return device_type + end + else + if (size[0] == resolution[0] and size[1] == resolution[1]) or # portrait + (size[1] == resolution[0] and size[0] == resolution[1]) # landscape + return device_type + end end end end raise "Unsupported screen size #{size} for path '#{path}'".red