Class: Deliver::AppScreenshot
- Inherits:
-
MetadataItem
- Object
- MetadataItem
- 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
-
#screen_size ⇒ Deliver::ScreenSize
The screen size (device type) specified at ScreenSize.
Attributes inherited from MetadataItem
Class Method Summary collapse
Instance Method Summary collapse
- #create_xml_node(doc, order_index) ⇒ Object
-
#initialize(path, screen_size = nil) ⇒ AppScreenshot
constructor
A new instance of AppScreenshot.
-
#is_valid? ⇒ Boolean
Validates the given screenshots (size and format).
- #name_for_xml_node ⇒ Object
Methods inherited from MetadataItem
Constructor Details
#initialize(path, screen_size = nil) ⇒ AppScreenshot
Returns a new instance of AppScreenshot.
28 29 30 31 32 33 34 35 36 |
# File 'lib/deliver/app_screenshot.rb', line 28 def initialize(path, screen_size = nil) super(path) 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
#screen_size ⇒ Deliver::ScreenSize
Returns the screen size (device type) specified at ScreenSize.
23 24 25 |
# File 'lib/deliver/app_screenshot.rb', line 23 def screen_size @screen_size end |
Class Method Details
.calculate_screen_size(path) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 |
# File 'lib/deliver/app_screenshot.rb', line 69 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 = { 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] ] } 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 end end end error = "Unsupported screen size #{size} for path '#{path}'" raise error end |
Instance Method Details
#create_xml_node(doc, order_index) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/deliver/app_screenshot.rb', line 38 def create_xml_node(doc, order_index) node = super(doc) # Screenshots have a slightly different xml code # <software_screenshot display_target="iOS-4-in" position="1"> # <size>295276</size> # <file_name>1-en-4-StartScreen.png</file_name> # <checksum type="md5">c00bd122a3ffbc79e26f1ae6210c7efd</checksum> # </software_screenshot> node['display_target'] = self.screen_size node['position'] = order_index return node end |
#is_valid? ⇒ Boolean
Validates the given screenshots (size and format)
61 62 63 64 65 66 67 |
# File 'lib/deliver/app_screenshot.rb', line 61 def is_valid? return false unless self.path.split(".").last == "png" size = FastImage.size(self.path) return self.screen_size == self.class.calculate_screen_size(self.path) end |
#name_for_xml_node ⇒ Object
56 57 58 |
# File 'lib/deliver/app_screenshot.rb', line 56 def name_for_xml_node 'software_screenshot' end |