flame_channel_parser 4.0.2 → 4.2.0

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/lib/xml_parser.rb CHANGED
@@ -2,16 +2,15 @@ require 'rexml/document'
2
2
  require "rexml/streamlistener"
3
3
 
4
4
  class FlameChannelParser::XMLParser < FlameChannelParser::Parser
5
- # Here you can assign a logger proc or a lambda that will be call'ed with progress reports
6
- attr_accessor :logger_proc
7
5
 
8
- # A SAX-based translation layer
6
+ # A SAX-based translation layer for XML-based setups.
7
+ # It will listen for specific tag names and transform the XML
8
+ # format into the old-school tab-delimited text format as it goes
9
9
  class XMLToSetup
10
10
  include REXML::StreamListener
11
11
 
12
- def initialize(vanilla_setup)
13
- @dest = vanilla_setup
14
- @indent = 0
12
+ def initialize(text_setup_destination_io)
13
+ @buffer = text_setup_destination_io
15
14
  @in_channel = false
16
15
  @path = []
17
16
  end
@@ -35,10 +34,10 @@ class FlameChannelParser::XMLParser < FlameChannelParser::Parser
35
34
  @in_channel = true
36
35
  # Compose the full channel name
37
36
 
38
- @dest.puts("Channel %s" % channel_name)
37
+ @buffer.puts("Channel %s" % channel_name)
39
38
  elsif element == "Key"
40
39
  @in_key = true
41
- @dest.puts("\tKey %d" % attributes["Index"].to_i)
40
+ @buffer.puts("\tKey %d" % attributes["Index"].to_i)
42
41
  end
43
42
  end
44
43
 
@@ -50,20 +49,20 @@ class FlameChannelParser::XMLParser < FlameChannelParser::Parser
50
49
  @path.pop
51
50
  if element == "Channel"
52
51
  @in_channel = false
53
- @dest.puts("\tEnd")
52
+ @buffer.puts("\tEnd")
54
53
  end
55
54
 
56
55
  if element == "Key"
57
56
  @in_key = false
58
- @dest.puts("\t\tEnd")
57
+ @buffer.puts("\t\tEnd")
59
58
  end
60
59
 
61
60
  if @in_key
62
- @dest.puts("\t\t" + transfo(element) + " " + @text)
61
+ @buffer.puts("\t\t" + transfo(element) + " " + @text)
63
62
  end
64
63
 
65
64
  if !@in_key && @in_channel
66
- @dest.puts("\t" + transfo(element) + " " + @text)
65
+ @buffer.puts("\t" + transfo(element) + " " + @text)
67
66
  end
68
67
  end
69
68
 
@@ -74,17 +73,13 @@ class FlameChannelParser::XMLParser < FlameChannelParser::Parser
74
73
 
75
74
  # Parses the setup passed in the IO. If a block is given to the method it will yield Channel
76
75
  # objects one by one instead of accumulating them into an array (useful for big setups)
77
- def parse(io)
76
+ def parse(io, &blk)
78
77
  # Ok this is gothic BUT needed. What we do is we transform the XML setup into the OLD
79
78
  # setup format, after which we run it through the OLD parser all the same.
80
79
  # I am almost sure that ADSK does the same.
81
80
  t = Tempfile.new("bx")
82
81
  REXML::Document.parse_stream(io, XMLToSetup.new(t))
83
82
  t.rewind
84
- if block_given?
85
- super(t, &Proc.new)
86
- else
87
- super(t)
88
- end
83
+ super(t, &blk)
89
84
  end
90
85
  end