Class: KeyFrame

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ KeyFrame

Returns a new instance of KeyFrame.



7
8
9
10
# File 'lib/key_frame.rb', line 7

def initialize(options = {})
  @time          = options[:time]
  @file_position = options[:file_position]
end

Instance Attribute Details

#file_positionObject

Returns the value of attribute file_position.



5
6
7
# File 'lib/key_frame.rb', line 5

def file_position
  @file_position
end

#timeObject

Returns the value of attribute time.



5
6
7
# File 'lib/key_frame.rb', line 5

def time
  @time
end

Class Method Details

.all_from_xml(keyframe_xml) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/key_frame.rb', line 12

def self.all_from_xml(keyframe_xml)
  times          = get_times(keyframe_xml.xpath("//times/value"))
  file_positions = get_file_positions(keyframe_xml.xpath("//filepositions/value"))
  
  count = 0
  key_frames = []
  while count < times.size do
    key_frames << KeyFrame.new(:time => times[count], :file_position => file_positions[count])
    count = count + 1
  end
  
  key_frames
end

.get_file_positions(file_positions_xml) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/key_frame.rb', line 34

def self.get_file_positions(file_positions_xml)
  file_positions = []
  file_positions_xml.children.each do |el|
    file_positions << el.inner_text.to_i
  end
  file_positions
end

.get_times(times_data_xml) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/key_frame.rb', line 26

def self.get_times(times_data_xml)
  times = []
  times_data_xml.children.each do |el|
    times << el.inner_text.to_f
  end
  times
end