flame_channel_parser 2.1.2 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ === 2.2.1 / 2011-31-07
2
+
3
+ * Fix keyframe indices in the progress reports
4
+
5
+ === 2.2.0 / 2011-31-07
6
+
7
+ * Output progress reports from the parser
8
+
1
9
  === 2.1.2 / 2011-29-06
2
10
 
3
11
  * Fixed automatic length detection in setups that do not specify their length
@@ -1,7 +1,7 @@
1
1
  module FlameChannelParser
2
- VERSION = '2.1.2'
2
+ VERSION = '2.2.1'
3
3
 
4
- # Parse a Flame setup into an array of Channel
4
+ # Parse a Flame setup into an array of Channel objects
5
5
  def self.parse(io)
6
6
  Parser.new.parse(io)
7
7
  end
data/lib/parser.rb CHANGED
@@ -3,8 +3,14 @@ require "forwardable"
3
3
  # Basic parser used for setups from versions up to 2011
4
4
  module FlameChannelParser
5
5
  class Parser
6
+
7
+ # Here you can assign a logger proc or a lambda that will be call'ed with progress reports
8
+ attr_accessor :logger_proc
9
+
6
10
  # Parses the setup passed in the IO
7
11
  def parse(io)
12
+ @do_logs = (@logger_proc.respond_to?(:call))
13
+
8
14
  channels = []
9
15
  node_name, node_type = nil, nil
10
16
 
@@ -15,13 +21,21 @@ module FlameChannelParser
15
21
  elsif line =~ NODE_NAME_MATCHER
16
22
  node_name = $1
17
23
  elsif line =~ CHANNEL_MATCHER && channel_is_useful?($1)
18
- channels << parse_channel(io, $1, node_type, node_name)
24
+ log("Parsing channel #{$1.inspect}")
25
+ channel = parse_channel(io, $1, node_type, node_name)
26
+ channels << channel
19
27
  end
20
28
  end
21
29
 
22
30
  channels
23
31
  end
24
-
32
+
33
+ # This method will be called internally with information on items being processed.
34
+ # The implementation just calls the logger_proc instance variable
35
+ def log(message)
36
+ @logger_proc.call(message) if @do_logs
37
+ end
38
+
25
39
  # Override this method to skip some channels, this will speedup
26
40
  # your code alot
27
41
  def channel_is_useful?(channel_name)
@@ -74,7 +88,11 @@ module FlameChannelParser
74
88
  end
75
89
 
76
90
  if line =~ KF_COUNT_MATCHER
77
- $1.to_i.times { c.push(extract_key_from(io)) }
91
+ num_keyframes = $1.to_i
92
+ num_keyframes.times do | idx |
93
+ log("Extracting keyframe %d of %d" % [idx + 1, num_keyframes])
94
+ c.push(extract_key_from(io))
95
+ end
78
96
  elsif line =~ BASE_VALUE_MATCHER# && empty?
79
97
  c.base_value = $1.to_f
80
98
  elsif line =~ EXTRAP_MATCHER
@@ -19,6 +19,19 @@ class TestFlameChannelParser < Test::Unit::TestCase
19
19
  assert_equal 12, chans[0].length
20
20
  end
21
21
 
22
+ def test_parsing_kronos_with_reports
23
+ logging_console = ""
24
+ data = File.open(File.dirname(__FILE__) + "/snaps/TW_TEST.F_Kronos")
25
+ parser = FlameChannelParser::Parser.new
26
+ parser.logger_proc = lambda do | log_message |
27
+ logging_console << log_message
28
+ end
29
+
30
+ parser.parse(data)
31
+ assert_match /Extracting keyframe 1 of 12/, logging_console
32
+ assert_no_match /Extracting keyframe 0 of 12/, logging_console, "Keyframe indices should not start at zero"
33
+ end
34
+
22
35
  def test_parsing
23
36
  data = File.open(File.dirname(__FILE__) + "/sample_channel.dat")
24
37
  channels = FlameChannelParser.parse(data)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: flame_channel_parser
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.1.2
5
+ version: 2.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Julik Tarkhanov
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-29 00:00:00 Z
13
+ date: 2011-07-31 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: update_hints
@@ -40,9 +40,9 @@ dependencies:
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ">="
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.9.4
45
+ version: "2.10"
46
46
  type: :development
47
47
  version_requirements: *id003
48
48
  description: |-