Class: MediaProcessingTool::XMLProcessor
- Inherits:
-
Object
- Object
- MediaProcessingTool::XMLProcessor
- Defined in:
- lib/media_processing_tool/xml_processor.rb
Constant Summary collapse
- DEFAULT_FILE_PATH_FIELD_NAME =
self.process
:path_on_file_system
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#publish ⇒ Boolean
Determines if the files parsed from the XML should be sent to a publisher.
Class Method Summary collapse
Instance Method Summary collapse
-
#document ⇒ Object
(also: #doc)
initialize_publisher.
- #document_type ⇒ Object
-
#initialize(params = { }) ⇒ XMLProcessor
constructor
A new instance of XMLProcessor.
-
#initialize_default_publisher(params = {}) ⇒ Object
initialize_mig.
-
#initialize_logger(params = { }) ⇒ Object
initialize.
-
#initialize_mig(params = {}) ⇒ Object
initialize_logger.
-
#process(xml, params = {}) ⇒ Object
publisher.
-
#process_document_files(_files, params = {}) ⇒ Object
process.
-
#process_document_sequences(params = {}) ⇒ Object
process_files.
-
#process_document_tracks(params = {}) ⇒ Object
process_sequences.
-
#publisher(params = {}) ⇒ Object
document_type.
-
#run_mig_on_file(full_file_path, params = {}) ⇒ Object
process_tracks.
Constructor Details
#initialize(params = { }) ⇒ XMLProcessor
Returns a new instance of XMLProcessor.
19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
14 15 16 |
# File 'lib/media_processing_tool/xml_processor.rb', line 14 def logger @logger end |
#publish ⇒ Boolean
Returns determines if the files parsed from the XML should be sent to a publisher.
17 18 19 |
# File 'lib/media_processing_tool/xml_processor.rb', line 17 def publish @publish end |
Class Method Details
.process(xml, params = { }) ⇒ Object
8 9 10 |
# File 'lib/media_processing_tool/xml_processor.rb', line 8 def self.process(xml, params = { }) end |
Instance Method Details
#document ⇒ Object Also known as: doc
initialize_publisher
46 47 48 |
# File 'lib/media_processing_tool/xml_processor.rb', line 46 def document @document end |
#document_type ⇒ Object
51 52 53 |
# File 'lib/media_processing_tool/xml_processor.rb', line 51 def document_type @identifier_document.type end |
#initialize_default_publisher(params = {}) ⇒ Object
initialize_mig
40 41 42 43 44 |
# 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 = { }) ⇒ Object
initialize
29 30 31 32 33 |
# 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 = {}) ⇒ Object
initialize_logger
35 36 37 38 |
# 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 = {}) ⇒ Object
publisher
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 = {}) ⇒ Object
process
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# 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. : { } 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 = {}) ⇒ Object
process_files
113 114 115 |
# 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 = {}) ⇒ Object
process_sequences
117 118 119 |
# 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 = {}) ⇒ Object
document_type
55 56 57 |
# File 'lib/media_processing_tool/xml_processor.rb', line 55 def publisher(params = {}) @publisher end |
#run_mig_on_file(full_file_path, params = {}) ⇒ Object
process_tracks
121 122 123 124 125 126 127 128 129 |
# 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 |