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



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

def frame
  @frame
end

#imageObject

the current image used for editing



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

def image
  @image
end

#screenshotObject

rubocop:disable Metrics/ClassLength



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

def screenshot
  @screenshot
end

#space_to_deviceObject

Returns the value of attribute space_to_device.



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

def space_to_device
  @space_to_device
end

Instance Method Details

#frame!(screenshot) ⇒ Object



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

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

  frame = load_frame
  if frame # Mac doesn't need a frame
    self.frame = MiniMagick::Image.open(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



44
45
46
47
48
49
50
# File 'frameit/lib/frameit/editor.rb', line 44

def load_frame
  color = fetch_frame_color
  if color
    screenshot.color = color
  end
  TemplateFinder.get_template(screenshot)
end

#prepare_imageObject



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

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

#rotation_for_device_orientationObject



56
57
58
59
60
# File 'frameit/lib/frameit/editor.rb', line 56

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