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! ⇒ Object
Add the device frame, this will also call the method that adds the background + title.
- #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.
- #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 |
# 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_58 return 'iPhone X' 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_PRO return 'iPad Pro' 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! ⇒ Object
Add the device frame, this will also call the method that adds the background + title
121 122 123 124 125 126 127 |
# File 'frameit/lib/frameit/screenshot.rb', line 121 def frame! if self.mac? MacEditor.new.frame!(self) else Editor.new.frame!(self) end end |
#frame_orientation ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'frameit/lib/frameit/screenshot.rb', line 83 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
112 113 114 |
# File 'frameit/lib/frameit/screenshot.rb', line 112 def landscape? return self.landscape_left? || self.landscape_right end |
#landscape_left? ⇒ Boolean
104 105 106 |
# File 'frameit/lib/frameit/screenshot.rb', line 104 def landscape_left? return (frame_orientation == :landscape_left) end |
#landscape_right? ⇒ Boolean
108 109 110 |
# File 'frameit/lib/frameit/screenshot.rb', line 108 def landscape_right? return (frame_orientation == :landscape_right) end |
#mac? ⇒ Boolean
73 74 75 |
# File 'frameit/lib/frameit/screenshot.rb', line 73 def mac? return device_name == 'MacBook' end |
#mini? ⇒ Boolean
Super old devices (iPhone 4)
69 70 71 |
# File 'frameit/lib/frameit/screenshot.rb', line 69 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
78 79 80 81 |
# File 'frameit/lib/frameit/screenshot.rb', line 78 def orientation_name return Orientation::PORTRAIT if size[0] < size[1] return Orientation::LANDSCAPE end |
#portrait? ⇒ Boolean
100 101 102 |
# File 'frameit/lib/frameit/screenshot.rb', line 100 def portrait? return (frame_orientation == :portrait) end |
#to_s ⇒ Object
116 117 118 |
# File 'frameit/lib/frameit/screenshot.rb', line 116 def to_s self.path end |
#triple_density? ⇒ Boolean
Is the device a 3x device? (e.g. iPhone 6 Plus, iPhone X)
64 65 66 |
# File 'frameit/lib/frameit/screenshot.rb', line 64 def triple_density? (screen_size == Deliver::AppScreenshot::ScreenSize::IOS_55 || screen_size == Deliver::AppScreenshot::ScreenSize::IOS_58) end |