lib/adiwg/mdtranslator.rb in adiwg-mdtranslator-1.1.1 vs lib/adiwg/mdtranslator.rb in adiwg-mdtranslator-1.2.0

- old
+ new

@@ -31,28 +31,10 @@ require 'adiwg/mdtranslator/writers/mdWriters' module ADIWG module Mdtranslator - def self.addFinalMessages - if $response[:readerStructurePass].nil? - $response[:readerStructureMessages].insert(0, 'Input file structure was not checked \n') - end - - if $response[:readerValidationPass].nil? - $response[:readerValidationMessages].insert(0, 'Validator was not called \n') - end - - if $response[:readerExecutionPass].nil? - $response[:readerExecutionMessages].insert(0, 'Reader was not called \n') - end - - if $response[:writerPass].nil? - $response[:writerMessages].insert(0, 'Writer not called \n') - end - end - def self.translate(file:, reader:, validate: 'normal', writer: nil, showAllTags: false) $showAllTags = showAllTags # the reader and writer specified in the translate parameter string should load and @@ -78,19 +60,19 @@ # set by reader # readerValidationMessages: an array of quoted string messages. If readerValidationPass # is 'false', set one or more messages to assist user fixing file schema validation # problems. Set by reader. # readerExecutionPass: 'true' if the reader completes the import of the input file into - # the internal object without errors set by reader + # the internal object without errors. set by reader. # readerExecutionMessages: an array of quoted string messages. If readerExecutionPass is # 'false', set one or more messages to assist user in fixing file data problems. # Set by reader. # writerName: name of the writer requested by the user, set from the translate parameter # list. if nil no write was requested and only validation of the input file will # be performed. # writerVersion: current version of the writer requested, set by writer - # writerFormat: format of the output from the writer, set by writer + # writerFormat: format of the output from the writer. Set by writer. # writerPass: true if the writer completes the creation of the output file without errors, # set by writer # writerMessages: an array of quoted string messages. If writerPass is 'false', set one # or more messages to assist user in fixing file data problems. Set by writer. # writerOutput: output file returned from the writer, set by writer @@ -116,24 +98,22 @@ writerOutput: nil } # handle readers if reader.nil? || reader == '' - $response[:readerStructureMessages] << 'Reader name is missing.' - $response[:readerValidationMessages] << 'Reader name is missing.' - $response[:readerExecutionMessages] << 'Reader name is missing.' - $response[:writerMessages] << 'Input file was not read.' - addFinalMessages() + $response[:readerExecutionPass] = false + $response[:readerExecutionMessages] << 'Reader name was not provided' return $response else require File.join(File.dirname(__FILE__), 'mdtranslator/readers/mdReaders') intObj = ADIWG::Mdtranslator::Readers.handleReader(file) - if intObj + # if readerExecutionPass is nil no error messages were set during exection + # and the execution is assumed to have been successful + if $response[:readerExecutionPass].nil? $response[:readerExecutionPass] = true - else - addFinalMessages() + elsif !$response[:readerExecutionPass] return $response end end # handle writers @@ -141,10 +121,9 @@ $response[:writerMessages] << 'Writer name was not provided.' else require File.join(File.dirname(__FILE__), 'mdtranslator/writers/mdWriters') ADIWG::Mdtranslator::Writers.handleWriter(intObj) end - addFinalMessages() return $response end end