lib/adiwg/mdtranslator.rb in adiwg-mdtranslator-1.0.0rc1 vs lib/adiwg/mdtranslator.rb in adiwg-mdtranslator-1.0.0rc2

- old
+ new

@@ -15,10 +15,11 @@ # Stan Smith 2014-12-01 added writer iso19110 (feature catalogue) # Stan Smith 2014-12-01 added translator version to $response # Stan Smith 2014-12-02 organized shared class/code/units folders for 19115-2, 19110 # Stan Smith 2014-12-11 refactored to handle namespacing readers and writers # Stan Smith 2015-01-15 changed translate() to keyword parameter list +# Stan Smith 2015-03-04 moved addFinalMessages into this module from rails app # add main directories to load_path $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'mdtranslator/internal')) require 'adiwg/mdtranslator/version' @@ -30,10 +31,28 @@ 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 # load and return this hash @@ -58,35 +77,35 @@ writerOutput: nil } # handle readers if reader.nil? || reader == '' - $response[:readerValidationPass] = false + $response[:readerStructureMessages] << 'Reader name is missing.' $response[:readerValidationMessages] << 'Reader name is missing.' - $response[:readerExecutionPass] = false - $response[:readerExecutionMessages] << 'Reader failed to complete.' + $response[:readerExecutionMessages] << 'Reader name is missing.' + $response[:writerMessages] << 'Input file was not read.' + addFinalMessages() return $response else require File.join(File.dirname(__FILE__), 'mdtranslator/readers/mdReaders') intObj = ADIWG::Mdtranslator::Readers.handleReader(file) if intObj $response[:readerExecutionPass] = true else - $response[:readerExecutionPass] = false - $response[:readerExecutionMessages] << 'Reader failed to complete.' + addFinalMessages() return $response end end # handle writers if writer.nil? || writer == '' - $response[:writerPass] = false - $response[:writerMessages] << 'Writer name is missing.' + $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