Class: Tracksperanto::Import::FlameStabilizer::ChannelBlock

Inherits:
Array
  • Object
show all
Includes:
Casts
Defined in:
lib/import/flame_stabilizer.rb

Instance Method Summary collapse

Methods included from Casts

#cast_to_float, #cast_to_int, #cast_to_string, included

Constructor Details

#initialize(io, channel_name) ⇒ ChannelBlock

Returns a new instance of ChannelBlock.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/import/flame_stabilizer.rb', line 29

def initialize(io, channel_name)
  @name = channel_name.strip
  
  base_value_matcher = /Value ([\-\d\.]+)/
  keyframe_count_matcher = /Size (\d+)/
  indent = nil
  
  keyframes = []
  
  while line = io.gets
    indent ||= line.scan(/^(\s+)/)[1]
    
    if line =~ keyframe_count_matcher
      $1.to_i.times { push(extract_key_from(io)) }
    elsif line =~ base_value_matcher && empty?
      self.base_value = $1
    elsif line.strip == "#{indent}End"
      break
    end
  end
  
  raise "Parsed a channel #{@name} with no keyframes" if (empty? && !base_value)
end

Instance Method Details

#<=>(o) ⇒ Object



25
26
27
# File 'lib/import/flame_stabilizer.rb', line 25

def <=>(o)
  @name <=> o.name
end

#extract_key_from(io) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/import/flame_stabilizer.rb', line 53

def extract_key_from(io)
  frame = nil
  frame_matcher = /Frame ([\-\d\.]+)/
  value_matcher = /Value ([\-\d\.]+)/
  
  until io.eof?
    line = io.gets
    if line =~ frame_matcher
      frame = $1.to_i
    elsif line =~ value_matcher
      value = $1.to_f
      return [frame,value]
    end
  end
  
  raise "Did not detect any keyframes!"
end