Class: Tween
Constant Summary
Constants inherited
from Transform
Transform::ALGORITHMS, Transform::DURATIONS, Transform::OPTIONS, Transform::Parsers
Instance Method Summary
collapse
-
#compute(from, to, delta) ⇒ Object
-
#initialize(element, options) ⇒ Tween
constructor
-
#parse(value) ⇒ Object
parses a value by its Parser, returning a hash of the parsed value and parser.
-
#prepare(element, property, from_to) ⇒ Object
-
#render(element, property, current_value, unit) ⇒ Object
-
#serve(value, unit) ⇒ Object
-
#set(current_value) ⇒ Object
-
#start(property, from, to) ⇒ Object
Methods inherited from Transform
add_transition, #cancel, #check, #complete, compute, #pause, #resume, #set_transition, #start_timer, #step, #stop_timer, #transition
Methods included from CodeEvents
#fire, #ignore, #upon
Constructor Details
#initialize(element, options) ⇒ Tween
Returns a new instance of Tween.
4
5
6
7
|
# File 'lib/source/redshift/tween.rb', line 4
def initialize(element, options)
@element = @subject = element
super(options)
end
|
Instance Method Details
#compute(from, to, delta) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/source/redshift/tween.rb', line 58
def compute(from,to,delta)
computed = []
(`Math.min(from.length, to.length)`).times do |i|
computed << {:value => from[i][:parser].compute(from[i][:value], to[i][:value], delta), :parser => from[i][:parser]}
end
return computed
end
|
#parse(value) ⇒ Object
parses a value by its Parser, returning a hash of the parsed value and parser
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/source/redshift/tween.rb', line 31
def parse(value)
value = value.to_s.split(' ')
returns = []
value.each do |val|
::Transform::Parsers.each do |parser|
parsed = parser.parse(val)
found = {:value => parsed, :parser => parser} if (parsed)
end
found = found || {:value => val, :parser => ::Transform::Parser::String}
returns << found
end
return returns
end
|
#prepare(element, property, from_to) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/source/redshift/tween.rb', line 15
def prepare(element, property, from_to)
to = from_to[1]
if (!to)
from_to[1] = from_to[0]
from_to[0] = element.styles[property]
end
parsed_from_to = []
from_to.each do |val|
parsed_from_to << self.parse(val)
end
return {:from => parsed_from_to[0], :to => parsed_from_to[1]}
end
|
#render(element, property, current_value, unit) ⇒ Object
50
51
52
|
# File 'lib/source/redshift/tween.rb', line 50
def render(element, property, current_value, unit)
element.set_style(property, self.serve(current_value, unit))
end
|
#serve(value, unit) ⇒ Object
54
55
56
|
# File 'lib/source/redshift/tween.rb', line 54
def serve(value, unit)
value[:parser].serve(value[:value], unit)
end
|
#set(current_value) ⇒ Object
45
46
47
48
|
# File 'lib/source/redshift/tween.rb', line 45
def set(current_value)
self.render(@element, @property, current_value[0], @options[:unit])
return self
end
|
#start(property, from, to) ⇒ Object
9
10
11
12
13
|
# File 'lib/source/redshift/tween.rb', line 9
def start(property, from, to)
@property = property
parsed = self.prepare(@element, property, [from, to])
super(parsed[:from], parsed[:to])
end
|