Class: MotionKit::Parent

Inherits:
Object show all
Defined in:
lib/motion-kit/helpers/parent.rb

Overview

Simple class that returns data about the parent element for use while setting the styles of a child element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ Parent

Returns a new instance of Parent.



9
10
11
# File 'lib/motion-kit/helpers/parent.rb', line 9

def initialize(element)
  @element = element
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



7
8
9
# File 'lib/motion-kit/helpers/parent.rb', line 7

def element
  @element
end

Instance Method Details

#centerObject



49
50
51
# File 'lib/motion-kit/helpers/parent.rb', line 49

def center
  CGPointMake(center_x, center_y) if width && height
end

#center_xObject



41
42
43
# File 'lib/motion-kit/helpers/parent.rb', line 41

def center_x
  width / 2.0 if width
end

#center_yObject



45
46
47
# File 'lib/motion-kit/helpers/parent.rb', line 45

def center_y
  height / 2.0 if height
end

#frameObject



13
14
15
# File 'lib/motion-kit/helpers/parent.rb', line 13

def frame
  try(:frame)
end

#heightObject



37
38
39
# File 'lib/motion-kit/helpers/parent.rb', line 37

def height
  try(:frame, :size, :height)
end

#originObject



17
18
19
# File 'lib/motion-kit/helpers/parent.rb', line 17

def origin
  try(:frame, :origin)
end

#sizeObject



21
22
23
# File 'lib/motion-kit/helpers/parent.rb', line 21

def size
  try(:frame, :size)
end

#widthObject



33
34
35
# File 'lib/motion-kit/helpers/parent.rb', line 33

def width
  try(:frame, :size, :width)
end

#xObject



25
26
27
# File 'lib/motion-kit/helpers/parent.rb', line 25

def x
  try(:frame, :origin, :x)
end

#yObject



29
30
31
# File 'lib/motion-kit/helpers/parent.rb', line 29

def y
  try(:frame, :origin, :y)
end