Class: Frameit::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/frameit/screenshot.rb

Overview

Represents one screenshot

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, color) ⇒ Screenshot

path: Path to screenshot color: Color to use for the frame



11
12
13
14
15
16
17
18
# File 'lib/frameit/screenshot.rb', line 11

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

#colorObject

the color to use for the frame (from Frameit::Color)



7
8
9
# File 'lib/frameit/screenshot.rb', line 7

def color
  @color
end

#pathObject

path to the screenshot



4
5
6
# File 'lib/frameit/screenshot.rb', line 4

def path
  @path
end

#screen_sizeObject

deliver screen size type, is unique per device type, used in device_name



6
7
8
# File 'lib/frameit/screenshot.rb', line 6

def screen_size
  @screen_size
end

#sizeObject

size in px array of 2 elements: height and width



5
6
7
# File 'lib/frameit/screenshot.rb', line 5

def size
  @size
end

Instance Method Details

#device_nameObject

Device name for a given screen size. Used to use the correct template



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/frameit/screenshot.rb', line 21

def device_name
  sizes = Deliver::AppScreenshot::ScreenSize
  case @screen_size
  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
end

#frame!Object

Add the device frame, this will also call the method that adds the background + title



81
82
83
84
85
86
87
# File 'lib/frameit/screenshot.rb', line 81

def frame!
  if self.mac?
    MacEditor.new.frame!(self)
  else
    Editor.new.frame!(self)
  end
end

#mac?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/frameit/screenshot.rb', line 62

def mac?
  return device_name == 'Mac'
end

#mini?Boolean

Super old devices (iPhone 4)

Returns:

  • (Boolean)


58
59
60
# File 'lib/frameit/screenshot.rb', line 58

def mini?
  (screen_size == Deliver::AppScreenshot::ScreenSize::IOS_35)
end

#orientation_nameObject

The name of the orientation of a screenshot. Used to find the correct template



67
68
69
70
# File 'lib/frameit/screenshot.rb', line 67

def orientation_name
  return Orientation::PORTRAIT if size[0] < size[1]
  return Orientation::LANDSCAPE
end

#portrait?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/frameit/screenshot.rb', line 72

def portrait?
  return (orientation_name == Orientation::PORTRAIT)
end

#to_sObject



76
77
78
# File 'lib/frameit/screenshot.rb', line 76

def to_s
  self.path
end

#triple_density?Boolean

Is the device a 3x device? (e.g. 6 Plus)

Returns:

  • (Boolean)


53
54
55
# File 'lib/frameit/screenshot.rb', line 53

def triple_density?
  (screen_size == Deliver::AppScreenshot::ScreenSize::IOS_55)
end