Class: Frameit::Screenshot
- Inherits:
-
Object
- Object
- Frameit::Screenshot
- Defined in:
- frameit/lib/frameit/screenshot.rb
Overview
Represents one screenshot
Instance Attribute Summary collapse
-
#color ⇒ Object
the color to use for the frame (from Frameit::Color).
-
#path ⇒ Object
path to the screenshot.
-
#screen_size ⇒ Object
deliver screen size type, is unique per device type, used in device_name.
-
#size ⇒ Object
size in px array of 2 elements: height and width.
Instance Method Summary collapse
-
#device_name ⇒ Object
Device name for a given screen size.
- #frame_orientation ⇒ Object
-
#initialize(path, color) ⇒ Screenshot
constructor
path: Path to screenshot color: Color to use for the frame.
- #landscape? ⇒ Boolean
- #landscape_left? ⇒ Boolean
- #landscape_right? ⇒ Boolean
- #mac? ⇒ Boolean
-
#mini? ⇒ Boolean
Super old devices (iPhone 4).
-
#orientation_name ⇒ Object
The name of the orientation of a screenshot.
-
#outdated? ⇒ Boolean
If the framed screenshot was generated before the screenshot file, then we must be outdated.
- #output_path ⇒ Object
- #portrait? ⇒ Boolean
- #to_s ⇒ Object
-
#triple_density? ⇒ Boolean
Is the device a 3x device? (e.g. iPhone 6 Plus, iPhone X).
Constructor Details
#initialize(path, color) ⇒ Screenshot
path: Path to screenshot color: Color to use for the frame
18 19 20 21 22 23 24 25 |
# File 'frameit/lib/frameit/screenshot.rb', line 18 def initialize(path, color) UI.user_error!("Couldn't find file at path '#{path}'") unless File.exist?(path) @color = color @path = path @size = FastImage.size(path) @screen_size = ENV["FRAMEIT_FORCE_DEVICE_TYPE"] || Deliver::AppScreenshot.calculate_screen_size(path) end |
Instance Attribute Details
#color ⇒ Object
the color to use for the frame (from Frameit::Color)
14 15 16 |
# File 'frameit/lib/frameit/screenshot.rb', line 14 def color @color end |
#path ⇒ Object
path to the screenshot
11 12 13 |
# File 'frameit/lib/frameit/screenshot.rb', line 11 def path @path end |
#screen_size ⇒ Object
deliver screen size type, is unique per device type, used in device_name
13 14 15 |
# File 'frameit/lib/frameit/screenshot.rb', line 13 def screen_size @screen_size end |
#size ⇒ Object
size in px array of 2 elements: height and width
12 13 14 |
# File 'frameit/lib/frameit/screenshot.rb', line 12 def size @size end |
Instance Method Details
#device_name ⇒ Object
Device name for a given screen size. Used to use the correct template
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'frameit/lib/frameit/screenshot.rb', line 28 def device_name # rubocop:disable Require/MissingRequireStatement sizes = Deliver::AppScreenshot::ScreenSize case @screen_size when sizes::IOS_65 return 'iPhone XS Max' when sizes::IOS_61 return 'iPhone XR' when sizes::IOS_58 return Frameit.config[:use_legacy_iphonex] ? 'iPhone X' : 'iPhone XS' when sizes::IOS_55 return Frameit.config[:use_legacy_iphone6s] ? 'iPhone 6s Plus' : 'iPhone 7 Plus' when sizes::IOS_47 return Frameit.config[:use_legacy_iphone6s] ? 'iPhone 6s' : 'iPhone 7' when sizes::IOS_40 return Frameit.config[:use_legacy_iphone5s] ? 'iPhone 5s' : 'iPhone SE' when sizes::IOS_35 return 'iPhone 4' when sizes::IOS_IPAD return 'iPad Air 2' when sizes::IOS_IPAD_10_5 return 'iPad Pro (10.5-inch)' when sizes::IOS_IPAD_11 return 'iPad Pro (11-inch)' when sizes::IOS_IPAD_PRO return 'iPad Pro' when sizes::IOS_IPAD_PRO_12_9 return 'iPad Pro (12.9-inch) (3rd generation)' when sizes::MAC return 'MacBook' else UI.error("Unknown device type for size #{@screen_size} for path '#{path}'") end # rubocop:enable Require/MissingRequireStatement end |
#frame_orientation ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'frameit/lib/frameit/screenshot.rb', line 93 def frame_orientation filename = File.basename(self.path, ".*") block = Frameit.config[:force_orientation_block] unless block.nil? orientation = block.call(filename) valid = [:landscape_left, :landscape_right, :portrait, nil] UI.user_error("orientation_block must return #{valid[0..-2].join(', ')} or nil") unless valid.include?(orientation) end puts("Forced orientation: #{orientation}") unless orientation.nil? return orientation unless orientation.nil? return :portrait if self.orientation_name == Orientation::PORTRAIT return :landscape_right # Default landscape orientation end |
#landscape? ⇒ Boolean
122 123 124 |
# File 'frameit/lib/frameit/screenshot.rb', line 122 def landscape? return self.landscape_left? || self.landscape_right end |
#landscape_left? ⇒ Boolean
114 115 116 |
# File 'frameit/lib/frameit/screenshot.rb', line 114 def landscape_left? return (frame_orientation == :landscape_left) end |
#landscape_right? ⇒ Boolean
118 119 120 |
# File 'frameit/lib/frameit/screenshot.rb', line 118 def landscape_right? return (frame_orientation == :landscape_right) end |
#mac? ⇒ Boolean
83 84 85 |
# File 'frameit/lib/frameit/screenshot.rb', line 83 def mac? return device_name == 'MacBook' end |
#mini? ⇒ Boolean
Super old devices (iPhone 4)
79 80 81 |
# File 'frameit/lib/frameit/screenshot.rb', line 79 def mini? (screen_size == Deliver::AppScreenshot::ScreenSize::IOS_35) end |
#orientation_name ⇒ Object
The name of the orientation of a screenshot. Used to find the correct template
88 89 90 91 |
# File 'frameit/lib/frameit/screenshot.rb', line 88 def orientation_name return Orientation::PORTRAIT if size[0] < size[1] return Orientation::LANDSCAPE end |
#outdated? ⇒ Boolean
If the framed screenshot was generated before the screenshot file, then we must be outdated.
132 133 134 135 |
# File 'frameit/lib/frameit/screenshot.rb', line 132 def outdated? return true unless File.exist?(output_path) return File.mtime(path) > File.mtime(output_path) end |
#output_path ⇒ Object
126 127 128 |
# File 'frameit/lib/frameit/screenshot.rb', line 126 def output_path path.gsub('.png', '_framed.png').gsub('.PNG', '_framed.png') end |
#portrait? ⇒ Boolean
110 111 112 |
# File 'frameit/lib/frameit/screenshot.rb', line 110 def portrait? return (frame_orientation == :portrait) end |
#to_s ⇒ Object
137 138 139 |
# File 'frameit/lib/frameit/screenshot.rb', line 137 def to_s self.path end |
#triple_density? ⇒ Boolean
Is the device a 3x device? (e.g. iPhone 6 Plus, iPhone X)
74 75 76 |
# File 'frameit/lib/frameit/screenshot.rb', line 74 def triple_density? (screen_size == Deliver::AppScreenshot::ScreenSize::IOS_55 || screen_size == Deliver::AppScreenshot::ScreenSize::IOS_58 || screen_size == Deliver::AppScreenshot::ScreenSize::IOS_65) end |