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).
-
#device ⇒ Object
device detected according to resolution, priority and settings.
-
#path ⇒ Object
path to the screenshot.
-
#size ⇒ Object
size in px array of 2 elements: height and width.
Instance Method Summary collapse
- #default_color ⇒ Object
- #deliver_screen_id ⇒ Object
-
#device_name ⇒ Object
Device name for a given screen size.
- #frame_orientation ⇒ Object
-
#initialize(path, color, config, platform_command) ⇒ Screenshot
constructor
path: Path to screenshot color: Color to use for the frame.
- #landscape? ⇒ Boolean
- #landscape_left? ⇒ Boolean
- #landscape_right? ⇒ Boolean
- #language ⇒ Object
- #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, config, platform_command) ⇒ Screenshot
path: Path to screenshot color: Color to use for the frame
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'frameit/lib/frameit/screenshot.rb', line 17 def initialize(path, color, config, platform_command) UI.user_error!("Couldn't find file at path '#{path}'") unless File.exist?(path) @color = color @path = path @size = FastImage.size(path) # There are three ways how we can get settings to Frameit: # - options.rb # - gets parameters via CLI (e. g. fastlane run frameit use_platform:"android") or fastfile (Fastlane's global # settings for a given project) # - see Parameters in the doc # - contains default values and validates values # - accessed via Frameit.config[:key] # - default value is either general platform from fastfile or IOS if run directly # - lowest priority # - commands_generator.rb # - commands entered directly to CLI (e. g. fastlane frameit android) # - they are passed via constructors to other classes # - higher priority than options.rb (user may enter a command to override fastfile's global setting) # - config_parser.rb # - gets key / values from Framefile.json # - see Advanced usage in the doc # - both default and specific values can be entered in the file (filtered by file name) # - accessed via ConfigParser.fetch_value(screenshot.path)[key] (the ConfigParser's instance is passed # to Screenshot's constructor as config, i.e. we call config[key]) # - should have the highest priority, because user might set a specific value for a specific screenshot which # should override CLI parameters and fastfile global setting platform = config['use_platform'] || platform_command || Frameit.config[:use_platform] @device = Device.find_device_by_id_or_name(config['force_device_type'] || Frameit.config[:force_device_type]) || Device.detect_device(path, platform) end |
Instance Attribute Details
#color ⇒ Object
the color to use for the frame (from Frameit::Color)
13 14 15 |
# File 'frameit/lib/frameit/screenshot.rb', line 13 def color @color end |
#device ⇒ Object
device detected according to resolution, priority and settings
12 13 14 |
# File 'frameit/lib/frameit/screenshot.rb', line 12 def device @device end |
#path ⇒ Object
path to the screenshot
10 11 12 |
# File 'frameit/lib/frameit/screenshot.rb', line 10 def path @path end |
#size ⇒ Object
size in px array of 2 elements: height and width
11 12 13 |
# File 'frameit/lib/frameit/screenshot.rb', line 11 def size @size end |
Instance Method Details
#default_color ⇒ Object
54 55 56 |
# File 'frameit/lib/frameit/screenshot.rb', line 54 def default_color @device.default_color end |
#deliver_screen_id ⇒ Object
58 59 60 |
# File 'frameit/lib/frameit/screenshot.rb', line 58 def deliver_screen_id @device.deliver_screen_id end |
#device_name ⇒ Object
Device name for a given screen size. Used to use the correct template
49 50 51 52 |
# File 'frameit/lib/frameit/screenshot.rb', line 49 def device_name @device.formatted_name # rubocop:enable Require/MissingRequireStatement end |
#frame_orientation ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'frameit/lib/frameit/screenshot.rb', line 82 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
111 112 113 |
# File 'frameit/lib/frameit/screenshot.rb', line 111 def landscape? return self.landscape_left? || self.landscape_right end |
#landscape_left? ⇒ Boolean
103 104 105 |
# File 'frameit/lib/frameit/screenshot.rb', line 103 def landscape_left? return (frame_orientation == :landscape_left) end |
#landscape_right? ⇒ Boolean
107 108 109 |
# File 'frameit/lib/frameit/screenshot.rb', line 107 def landscape_right? return (frame_orientation == :landscape_right) end |
#language ⇒ Object
126 127 128 |
# File 'frameit/lib/frameit/screenshot.rb', line 126 def language @language ||= Pathname.new(path).parent.basename.to_s end |
#mac? ⇒ Boolean
72 73 74 |
# File 'frameit/lib/frameit/screenshot.rb', line 72 def mac? device_name == 'MacBook' end |
#mini? ⇒ Boolean
Super old devices (iPhone 4)
68 69 70 |
# File 'frameit/lib/frameit/screenshot.rb', line 68 def mini? !device.density_ppi.nil? && device.density_ppi < 300 end |
#orientation_name ⇒ Object
The name of the orientation of a screenshot. Used to find the correct template
77 78 79 80 |
# File 'frameit/lib/frameit/screenshot.rb', line 77 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.
121 122 123 124 |
# File 'frameit/lib/frameit/screenshot.rb', line 121 def outdated? return true unless File.exist?(output_path) return File.mtime(path) > File.mtime(output_path) end |
#output_path ⇒ Object
115 116 117 |
# File 'frameit/lib/frameit/screenshot.rb', line 115 def output_path path.gsub('.png', '_framed.png').gsub('.PNG', '_framed.png') end |
#portrait? ⇒ Boolean
99 100 101 |
# File 'frameit/lib/frameit/screenshot.rb', line 99 def portrait? return (frame_orientation == :portrait) end |
#to_s ⇒ Object
130 131 132 |
# File 'frameit/lib/frameit/screenshot.rb', line 130 def to_s self.path end |
#triple_density? ⇒ Boolean
Is the device a 3x device? (e.g. iPhone 6 Plus, iPhone X)
63 64 65 |
# File 'frameit/lib/frameit/screenshot.rb', line 63 def triple_density? !device.density_ppi.nil? && device.density_ppi > 400 end |