class MediaProcessingTool::XMLProcessor
Constants
- DEFAULT_FILE_PATH_FIELD_NAME
Attributes
logger[RW]
publish[RW]
@return [Boolean] determines if the files parsed from the XML should be sent to a publisher
Public Class Methods
new(params = { })
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 19 def initialize(params = { }) initialize_logger(params) @publish = params.fetch(:publish, true) @default_file_path_field_name = params[:@default_file_path_field_name] || DEFAULT_FILE_PATH_FIELD_NAME initialize_mig(params.dup) initialize_default_publisher(params.dup) end
process(xml, params = { })
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 8 def self.process(xml, params = { }) end
Public Instance Methods
document()
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 46 def document @document end
Also aliased as: doc
document_type()
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 51 def document_type @identifier_document.type end
initialize_default_publisher(params = {})
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 40 def initialize_default_publisher(params = {}) logger.debug { "Initializing Default Publisher. #{params}" } params[:file_path_field_name] = @default_file_path_field_name @default_publisher = MediaProcessingTool::Publisher.new(params) end
initialize_logger(params = { })
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 29 def initialize_logger(params = { }) @logger = params[:logger] ||= Logger.new(params[:log_to] || STDOUT) logger.level = params[:log_level] if params[:log_level] params[:logger] = logger unless params[:logger] end
initialize_mig(params = {})
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 35 def initialize_mig(params = {}) logger.debug { "Initializing Media Processing Tool. #{params}" } @mig = MediaInformationGatherer.new(params) end
process(xml, params = {})
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 59 def process(xml, params = {}) @xml_file_path = File.exists?(xml) ? xml : nil @document = XMLParser.parse(xml) @identifier_document = XMLParser.identifier_document @params = params @files = document.respond_to?(:files) ? document.files : [ ] @results = { } #force_default_publisher = params[:force_default_publisher] force_default_publisher = params.fetch(:force_default_publisher, true) if force_default_publisher @publisher = @default_publisher.dup @results[:files] = process_document_files(@files, :publisher => @publisher) if @files else # TODO PUT IN DYNAMIC PUBLISHER HANDLING doc_type = document_type end #{ :files => files, :sequences => sequences } @results end
process_document_files(_files, params = {})
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 85 def process_document_files(_files, params = {}) publisher = params[:publisher] run_mig = params.fetch(:run_mig, true) _results = [ ] total_files = _files.length current_file_counter = 0 _files.each do |file| current_file_counter += 1 full_file_path = file[@default_file_path_field_name] logger.debug { "Processing Document File #{current_file_counter} of #{total_files}. File Path: #{full_file_path}" } if run_mig _mig = run_mig_on_file(full_file_path) file[:metadata_sources] = _mig ? _mig.metadata_sources : { } else logger.debug { 'Media Information Gathering SKIPPED. run_mig set to false.' } end file[:xml_file_path] = @xml_file_path file_result = { file: file } file_result[:publish_result] = publisher.process(file) if publish and publisher _results << file_result end _results end
process_document_sequences(params = {})
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 113 def process_document_sequences(params = {}) sequences = doc.respond_to?(:sequences) ? doc.sequences : [ ] end
process_document_tracks(params = {})
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 117 def process_document_tracks(params = {}) tracks = doc.respond_to?(:tracks) ? doc.tracks : [ ] end
publisher(params = {})
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 55 def publisher(params = {}) @publisher end
run_mig_on_file(full_file_path, params = {})
click to toggle source
# File lib/media_processing_tool/xml_processor.rb, line 121 def run_mig_on_file(full_file_path, params = {}) if File.exists?(full_file_path) @mig.run(full_file_path) return @mig else logger.debug { "Media Information Gathering SKIPPED. File Not Found. #{full_file_path}" } return false end end