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

- old
+ new

@@ -18,13 +18,10 @@ module ADIWG module Mdtranslator module Readers module MdJson - # set reader namespace - $ReaderNS = ADIWG::Mdtranslator::Readers::MdJson - def self.readFile(file) # set anticipated format of file in $response $response[:readerFormat] = 'json' # receive json file into ruby hash @@ -50,11 +47,11 @@ $ReaderNS.validate(file) if !$response[:readerValidationPass] return false end - # unpack mdJson file + # load mdJson file into internal object require readerModule('module_mdJson') intObj = $ReaderNS.unpack(@hMdJson) return intObj end @@ -65,21 +62,22 @@ begin @hMdJson = JSON.parse(file) $response[:readerStructurePass] = true rescue JSON::JSONError => err $response[:readerStructurePass] = false - $response[:readerStructureMessages] << err - return + $response[:readerStructureMessages] << 'JSON Parsing Failed - see following message(s):\n' + $response[:readerStructureMessages] << err.to_s.slice(0,300) end end def self.checkVersionName # find version name on the input json file if @hMdJson.has_key?('version') hVersion = @hMdJson['version'] else $response[:readerStructurePass] = false + $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n' $response[:readerStructureMessages] << 'The input file is missing the version:{} block.' return end # check the version name @@ -87,25 +85,27 @@ s = hVersion['name'] if !s.nil? $response[:readerFound] = s else $response[:readerStructurePass] = false - $response[:readerStructureMessages] << 'The input file version name is missing.' + $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n' + $response[:readerStructureMessages] << 'The input file version: => name: is missing.' return end else $response[:readerStructurePass] = false - $response[:readerStructureMessages] << "The input file version:{} block is missing the 'name' attribute." + $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n' + $response[:readerStructureMessages] << "The input file version:{} block is missing the 'name:' attribute." return end # check the version name is 'mdJson' if s != 'mdJson' $response[:readerStructurePass] = false - $response[:readerStructureMessages] << "The mdTranslator reader expected the input file version name to be 'mdJson'." + $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n' + $response[:readerStructureMessages] << "The mdTranslator reader expected the input file version: name: to be 'mdJson'." $response[:readerStructureMessages] << "Version name found was: '#{s}'." - return end end def self.checkVersionNumber # find version number on the input json file @@ -115,11 +115,12 @@ if !s.nil? $response[:readerVersionFound] = s end else $response[:readerStructurePass] = false - $response[:readerStructureMessages] << "The input file version:{} block is missing the 'version' number attribute." + $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n' + $response[:readerStructureMessages] << "The input file version:{} block is missing the 'version:' number attribute." return end # test the reader version requested is supported # remove maintenance release number first @@ -129,19 +130,20 @@ if aVersionParts.length >= 2 readerVersion = aVersionParts[0] +'.' + aVersionParts[1] dir = File.join(File.dirname(__FILE__), 'modules_' + readerVersion) if !File.directory?(dir) $response[:readerStructurePass] = false + $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n' $response[:readerStructureMessages] << 'The input file version is not supported.' $response[:readerStructureMessages] << "mdJson version requested was '#{s}'" return end $response[:readerVersionUsed] = readerVersion else $response[:readerStructurePass] = false + $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n' $response[:readerStructureMessages] << 'The input file version number must be in the form MAJOR.MINOR.PATCH, e.g. 1.2.3' $response[:readerStructureMessages] << 'Note the PATCH number is optional.' - return end end # require modules for the requested version def self.readerModule(moduleName)