Class: Inkcite::Animation::Keyframe

Inherits:
Object
  • Object
show all
Defined in:
lib/inkcite/facade/keyframe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(percent, ctx, styles = {}) ⇒ Keyframe

Returns a new instance of Keyframe.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/inkcite/facade/keyframe.rb', line 15

def initialize percent, ctx, styles={}

  # Animation percents are always rounded to the nearest whole number.
  @percent = percent
  @end_percent = nil
  @duration = nil

  # Instantiate a new Style for this percentage.
  @style = Inkcite::Renderer::Style.new(nil, ctx, styles)

end

Instance Attribute Details

#durationObject

Ending percentage the animation stays at this keyframe. For example, a keyframe that starts at 20% and has a duration of 19.9% would render as 25%, 39.9% { … }



10
11
12
# File 'lib/inkcite/facade/keyframe.rb', line 10

def duration
  @duration
end

#end_percentObject

Alternative to duration, the ending percentage



13
14
15
# File 'lib/inkcite/facade/keyframe.rb', line 13

def end_percent
  @end_percent
end

#percentObject (readonly)

Returns the value of attribute percent.



5
6
7
# File 'lib/inkcite/facade/keyframe.rb', line 5

def percent
  @percent
end

#styleObject (readonly)

Returns the value of attribute style.



5
6
7
# File 'lib/inkcite/facade/keyframe.rb', line 5

def style
  @style
end

Instance Method Details

#[](key) ⇒ Object



27
28
29
# File 'lib/inkcite/facade/keyframe.rb', line 27

def [] key
  @style[key]
end

#[]=(key, val) ⇒ Object



31
32
33
# File 'lib/inkcite/facade/keyframe.rb', line 31

def []= key, val
  @style[key] = val
end

#add(key, val) ⇒ Object

For style chaining - e.g. keyframe.add(:key1, ‘val’).add(:key)



36
37
38
39
# File 'lib/inkcite/facade/keyframe.rb', line 36

def add key, val
  @style[key] = val
  self
end

#add_with_prefixes(key, val, ctx) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/inkcite/facade/keyframe.rb', line 50

def add_with_prefixes key, val, ctx

  ctx.prefixes.each do |prefix|
    _key = "#{prefix}#{key}".to_sym
    self[_key] = val
  end

  self
end

#append(key, val) ⇒ Object

Appends a value to an existing key



42
43
44
45
46
47
48
# File 'lib/inkcite/facade/keyframe.rb', line 42

def append key, val

  @style[key] ||= ''
  @style[key] << ' ' unless @style[key].blank?
  @style[key] << val

end

#to_css(prefix) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/inkcite/facade/keyframe.rb', line 60

def to_css prefix
  css = "#{@percent}%"

  ends_at = calc_ends_at
  css << ", #{ends_at}%" if ends_at

  css << ' { '
  css << @style.to_inline_css(prefix)
  css << ' }'
  css
end