lib/adiwg/mdtranslator/readers/mdJson/mdJson_reader.rb in adiwg-mdtranslator-1.1.1 vs lib/adiwg/mdtranslator/readers/mdJson/mdJson_reader.rb in adiwg-mdtranslator-1.2.0
- old
+ new
@@ -10,10 +10,11 @@
# Stan Smith 2014-07-08 moved json schema version testing to 'adiwg_1_get_version'
# Stan Smith 2014-08-18 add json name/version to internal object
# Stan Smith 2014-12-01 add data dictionary
# Stan Smith 2014-12-03 changed class name to MdJsonReader from AdiwgJsonReader
# Stan Smith 2014-12-11 refactored to handle namespacing readers and writers
+# Stan Smith 2015-06-12 added method to lookup contact in contact array
require 'json'
module ADIWG
module Mdtranslator
@@ -49,13 +50,18 @@
return false
end
# load mdJson file into internal object
require readerModule('module_mdJson')
- intObj = $ReaderNS.unpack(@hMdJson)
- return intObj
+ # instance classes needed in script
+ intMetadataClass = InternalMetadata.new
+ # create new internal metadata container for the reader
+ @intObj = intMetadataClass.newBase
+ $ReaderNS.unpack(@intObj, @hMdJson)
+ return @intObj
+
end
def self.parseJson(file)
# validate the input file structure
# test for valid json syntax by attempting to parse the file
@@ -160,9 +166,22 @@
# no prior version directory found
# ... file not found
return nil
end
return file
+ end
+
+ # find the array pointer for a contact
+ def self.findContact(contactId)
+ pointer = nil
+ i = 0
+ @intObj[:contacts].each do |contact|
+ if contact[:contactId] == contactId
+ pointer = i
+ end
+ i += 1
+ end
+ return pointer
end
end
end
end