class FlameChannelParser::XMLParser::XMLToSetup

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

Public Class Methods

new(text_setup_destination_io) click to toggle source
# File lib/xml_parser.rb, line 12
def initialize(text_setup_destination_io)
  @buffer = text_setup_destination_io
  @in_channel = false
  @path = []
end

Public Instance Methods

tag_end(element) click to toggle source
# 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) click to toggle source

<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>

# 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) click to toggle source
# File lib/xml_parser.rb, line 44
def text(text)
  @text = text
end
transfo(t) click to toggle source
# File lib/xml_parser.rb, line 69
def transfo(t)
  t == "Extrap" ? "Extrapolation" : t
end