Class: Frameit::Editor

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

Overview

Currently the class is 2 lines too long. Reevaluate refactoring when it’s length changes significantly

Direct Known Subclasses

MacEditor

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#frameObject

the frame of the device



14
15
16
# File 'frameit/lib/frameit/editor.rb', line 14

def frame
  @frame
end

#imageObject

the current image used for editing



15
16
17
# File 'frameit/lib/frameit/editor.rb', line 15

def image
  @image
end

#screenshotObject

rubocop:disable Metrics/ClassLength



13
14
15
# File 'frameit/lib/frameit/editor.rb', line 13

def screenshot
  @screenshot
end

#space_to_deviceObject

Returns the value of attribute space_to_device.



16
17
18
# File 'frameit/lib/frameit/editor.rb', line 16

def space_to_device
  @space_to_device
end

Instance Method Details

#frame!(screenshot) ⇒ Object



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

def frame!(screenshot)
  self.screenshot = screenshot
  prepare_image

  if load_frame # Mac doesn't need a frame
    self.frame = MiniMagick::Image.open(load_frame)
    # Rotate the frame according to the device orientation
    self.frame.rotate(self.rotation_for_device_orientation)
  elsif self.class == Editor
    # Couldn't find device frame (probably an iPhone 4, for which there are no images available any more)
    # Message is already shown elsewhere
    return
  end

  if should_add_title?
    @image = complex_framing
  else
    # easy mode from 1.0 - no title or background
    put_into_frame # put it in the frame
  end

  store_result # write to file system
end

#load_frameObject



42
43
44
# File 'frameit/lib/frameit/editor.rb', line 42

def load_frame
  TemplateFinder.get_template(screenshot)
end

#prepare_imageObject



46
47
48
# File 'frameit/lib/frameit/editor.rb', line 46

def prepare_image
  @image = MiniMagick::Image.open(screenshot.path)
end

#rotation_for_device_orientationObject



50
51
52
53
54
# File 'frameit/lib/frameit/editor.rb', line 50

def rotation_for_device_orientation
  return 90 if self.screenshot.landscape_right?
  return -90 if self.screenshot.landscape_left?
  return 0
end