Class: FlameChannelParser::XMLParser::XMLToSetup

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/xml_parser.rb

Overview

A SAX-based translation layer for XML-based setups. It will listen for specific tag names and transform the XML format into the old-school tab-delimited text format as it goes

Instance Method Summary collapse

Constructor Details

#initialize(text_setup_destination_io) ⇒ XMLToSetup

Returns a new instance of XMLToSetup.



12
13
14
15
16
# File 'lib/xml_parser.rb', line 12

def initialize(text_setup_destination_io)
  @buffer = text_setup_destination_io
  @in_channel = false
  @path = []
end

Instance Method Details

#tag_end(element) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/xml_parser.rb', line 48

def tag_end(element)
  @path.pop
  if element == "Channel"
    @in_channel = false
    @buffer.puts("\tEnd")
  end
  
  if element == "Key"
    @in_key = false
    @buffer.puts("\t\tEnd")
  end
  
  if @in_key
    @buffer.puts("\t\t" + transfo(element) + " " + @text)
  end
  
  if !@in_key && @in_channel
    @buffer.puts("\t" + transfo(element) + " " + @text)
  end
end

#tag_start(element, attributes) ⇒ Object

<KFrames>

<Key Index="0">
  <Frame>1.000000</Frame>
  <Value>100</Value>
  <RHandleX>1.297667</RHandleX>
  <RHandleY>100.000000</RHandleY>
  <LHandleX>0.750000</LHandleX>
  <LHandleY>100.000000</LHandleY>
  <CurveMode>hermite</CurveMode>
  <CurveOrder>linear</CurveOrder>
</Key>

</KFrames>



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xml_parser.rb', line 30

def tag_start(element, attributes)
  @path.push(element)
  if element == "Channel"
    channel_name = attributes["Name"]
    @in_channel = true
    # Compose the full channel name
    
    @buffer.puts("Channel %s" % channel_name)
  elsif element == "Key"
    @in_key = true
    @buffer.puts("\tKey %d" % attributes["Index"].to_i)
  end
end

#text(text) ⇒ Object



44
45
46
# File 'lib/xml_parser.rb', line 44

def text(text)
  @text = text
end

#transfo(t) ⇒ Object



69
70
71
# File 'lib/xml_parser.rb', line 69

def transfo(t)
  t == "Extrap" ? "Extrapolation" : t
end