Class: Deliver::AppScreenshot
- Inherits:
-
Object
- Object
- Deliver::AppScreenshot
- Defined in:
- 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
-
#language ⇒ Object
Returns the value of attribute language.
-
#path ⇒ Object
Returns the value of attribute path.
-
#screen_size ⇒ Deliver::ScreenSize
The screen size (device type) specified at ScreenSize.
Class Method Summary collapse
- .calculate_screen_size(path) ⇒ Object
-
.devices ⇒ Object
rubocop:enable Style/PredicateName.
Instance Method Summary collapse
-
#device_type ⇒ Object
The iTC API requires a different notation for the device.
-
#formatted_name ⇒ Object
Nice name.
-
#initialize(path, language, screen_size = nil) ⇒ AppScreenshot
constructor
A new instance of AppScreenshot.
-
#is_valid? ⇒ Boolean
Validates the given screenshots (size and format) rubocop:disable Style/PredicateName.
Constructor Details
#initialize(path, language, screen_size = nil) ⇒ AppScreenshot
Returns a new instance of AppScreenshot.
40 41 42 43 44 45 46 47 48 |
# File 'lib/deliver/app_screenshot.rb', line 40 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 Helper.log.error "Looks like the screenshot given (#{path}) does not match the requirements of #{screen_size}" unless self.is_valid? end |
Instance Attribute Details
#language ⇒ Object
Returns the value of attribute language.
34 35 36 |
# File 'lib/deliver/app_screenshot.rb', line 34 def language @language end |
#path ⇒ Object
Returns the value of attribute path.
32 33 34 |
# File 'lib/deliver/app_screenshot.rb', line 32 def path @path end |
#screen_size ⇒ Deliver::ScreenSize
Returns the screen size (device type) specified at ScreenSize.
30 31 32 |
# File 'lib/deliver/app_screenshot.rb', line 30 def screen_size @screen_size end |
Class Method Details
.calculate_screen_size(path) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/deliver/app_screenshot.rb', line 139 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 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 end |
.devices ⇒ Object
rubocop:enable Style/PredicateName
91 92 93 94 95 96 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 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/deliver/app_screenshot.rb', line 91 def self.devices return { ScreenSize::IOS_55 => [ [1080, 1920], [1242, 2208] ], ScreenSize::IOS_47 => [ [750, 1334] ], ScreenSize::IOS_40 => [ [640, 1136], [640, 1096], [1136, 600] # landscape status bar is smaller ], ScreenSize::IOS_35 => [ [640, 960], [640, 920], [960, 600] # landscape status bar is smaller ], ScreenSize::IOS_IPAD => [ [1024, 748], [1024, 768], [2048, 1496], [2048, 1536], [768, 1004], [768, 1024], [1536, 2008], [1536, 2048] ], ScreenSize::IOS_IPAD_PRO => [ [2732, 2048], [2048, 2732] ], ScreenSize::MAC => [ [1280, 800], [1440, 900], [2880, 1800], [2560, 1600] ], ScreenSize::IOS_APPLE_WATCH => [ [312, 390] ], ScreenSize::APPLE_TV => [ [1920, 1080] ] } end |
Instance Method Details
#device_type ⇒ Object
The iTC API requires a different notation for the device
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/deliver/app_screenshot.rb', line 51 def device_type matching = { ScreenSize::IOS_35 => "iphone35", ScreenSize::IOS_40 => "iphone4", 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::APPLE_TV => "appleTV" } return matching[self.screen_size] end |
#formatted_name ⇒ Object
Nice name
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/deliver/app_screenshot.rb', line 67 def formatted_name matching = { ScreenSize::IOS_35 => "iPhone 4", ScreenSize::IOS_40 => "iPhone 5", 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::APPLE_TV => "Apple TV" } return matching[self.screen_size] end |
#is_valid? ⇒ Boolean
Validates the given screenshots (size and format) rubocop:disable Style/PredicateName
84 85 86 87 88 |
# File 'lib/deliver/app_screenshot.rb', line 84 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 |