Class: AdiwgJsonReader
- Inherits:
-
Object
- Object
- AdiwgJsonReader
- Defined in:
- lib/adiwg/mdtranslator/readers/adiwgJson/adiwgJson_reader.rb
Instance Method Summary collapse
-
#initialize ⇒ AdiwgJsonReader
constructor
A new instance of AdiwgJsonReader.
- #unpack(jsonObj) ⇒ Object
Constructor Details
#initialize ⇒ AdiwgJsonReader
Returns a new instance of AdiwgJsonReader.
19 20 |
# File 'lib/adiwg/mdtranslator/readers/adiwgJson/adiwgJson_reader.rb', line 19 def initialize end |
Instance Method Details
#unpack(jsonObj) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/adiwg/mdtranslator/readers/adiwgJson/adiwgJson_reader.rb', line 22 def unpack(jsonObj) # instance classes needed in script intMetadataClass = InternalMetadata.new # create new internal metadata container for the reader intBase = intMetadataClass.newBase # convert the received JSON to a Ruby hash hashObj = JSON.parse(jsonObj) # get json schema name and version if hashObj.has_key?('version') hVersion = hashObj['version'] unless hVersion.empty? if hVersion.has_key?('name') s = hVersion['name'] if !s.nil? intBase[:jsonVersion][:name] = s end end if hVersion.has_key?('version') s = hVersion['version'] if !s.nil? intBase[:jsonVersion][:version] = s end end end end # contact # load the array of contacts from the json object # ... the contacts array uses a local id to reference the # ... contact in the array from elsewhere in the json metadata if hashObj.has_key?('contact') aContacts = hashObj['contact'] aContacts.each do |hContact| unless hContact.empty? intBase[:contacts] << Adiwg_Contact.unpack(hContact) end end end # add default contacts intBase[:contacts].concat(Adiwg_Contact.setDefaultContacts) # metadata # load metadata from the hash object if hashObj.has_key?('metadata') hMetadata = hashObj['metadata'] intBase[:metadata] = Adiwg_Metadata.unpack(hMetadata) end # return ADIwg internal container return intBase end |