class FinalCutPro::XMLParser::Common

Attributes

files[RW]
logger[RW]
sequences[RW]

Public Class Methods

new(xml, options = { }) click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 17
def initialize(xml, options = { })
  @logger = FinalCutPro.process_options_for_logger(options)
  @xml_document = xml_as_document(xml)
end
xml_as_document(xml, options = { }) click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 13
def self.xml_as_document(xml, options = { })
  AXML.xml_as_document(xml)
end

Public Instance Methods

is_clip?() click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 103
def is_clip?
  top_level_container == 'clip'
end
is_fcpxml?() click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 88
def is_fcpxml?
  root_type == 'fcpxml'
end
is_project?() click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 107
def is_project?
  top_level_container == 'project'
end
is_sequence?() click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 111
def is_sequence?
  top_level_container == 'sequence'
end
is_xmeml?() click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 84
def is_xmeml?
  root_type == 'xmeml'
end
root() click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 75
def root
  xml_document.root
end
root_type() click to toggle source

Gets the

# File lib/final_cut_pro/xml_parser/common.rb, line 80
def root_type
  @root_type ||= root.name
end
to_hash(keys_to_symbols = true) click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 26
def to_hash(keys_to_symbols = true)
  rt = keys_to_symbols ? root_type.to_sym : root_type
  { rt => xml_node_to_hash(root, keys_to_symbols) }
end
top_level_container() click to toggle source

The tag inside of the xmeml or fcpxml tag

# File lib/final_cut_pro/xml_parser/common.rb, line 99
def top_level_container
  @top_level_container ||= root.children.first.name
end
version() click to toggle source

The fcpxml or xmeml version

# File lib/final_cut_pro/xml_parser/common.rb, line 94
def version
  @version ||= root.attributes['version']
end
xml_as_document(xml) click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 22
def xml_as_document(xml)
  self.class.xml_as_document(xml)
end
xml_document() click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 70
def xml_document
  @xml_document
end
Also aliased as: xmldoc
xml_node_to_hash(node, keys_to_symbols = true) click to toggle source
# File lib/final_cut_pro/xml_parser/common.rb, line 31
def xml_node_to_hash(node, keys_to_symbols = true)
  # If we are at the root of the document, start the hash
  return node.content.to_s unless node.element?
  result_hash = {}

  # Add the attributes for the node to the hash
  node.each_attr { |a| a_name = keys_to_symbols ? a.name.to_sym : a.name; result_hash[a_name] = a.value }
  return result_hash.empty? ? nil : result_hash unless node.children?

  node.each_child do |child|
    result = xml_node_to_hash(child, keys_to_symbols)

    if child.name == 'text' or child.cdata?
      return result if !child.next? and !child.prev?
      next
    end

    begin
      key = keys_to_symbols ? child.name.to_sym : child.name
    rescue
      # FCP CDATA Fields usually fail to convert to a sym.
      logger.error { "Error Converting #{child.name} to symbol.\nCHILD: #{child.inspect}\nNODE: #{node}" }
      key = child.name
    end
    if result_hash[key]
      # We don't want to overwrite a value for an existing key so the value needs to be an array
      if result_hash[key].is_a?(Array)
        result_hash[key] << result
      else
        # Create an array
        result_hash[key] = [ result_hash[key], result ]
      end
    else
      result_hash[key] = result
    end
  end
  return result_hash
end
xmldoc()
Alias for: xml_document