Sha256: c9c731f03bf526d4da93046197704835d8125c977643edfce93eb5a4c7e65e04

Contents?: true

Size: 1.83 KB

Versions: 9

Compression:

Stored size: 1.83 KB

Contents

require "rexml/document"
require "document/data"

module Baclava
  
  class Reader
    
    #Reads a baclava document amd returns a hash of Document::Data objects
    def self.read(xml)
      if xml.kind_of?(REXML::Document)
      	document = xml
      else
        document = REXML::Document.new(xml)
      end
      root = document.root
      raise "'#{root.name}' doesn't appear to be a data thing!" if root.name != "dataThingMap"
      
      create_data_map(root)
    end
    
    def self.create_data_map(element)
      data_map = {}
      
      element.each_element('b:dataThing') { |datathing|
        key = datathing.attribute('key').value
        data = Document::Data.new
        data_map[key] = data
        datathing.each_element('b:myGridDataDocument')  { |dataDocument|
          dataDocument.each_element('s:metadata')  { |metadata| data.annotation = get_metadata(metadata) }
          dataDocument.each_element('b:partialOrder') { |partialOrder| data.value = get_list(partialOrder) }
          dataDocument.each_element('b:dataElement')  { |dataElement| data.value = get_element(dataElement) }
        }
      }
      
      data_map   
    end
    
    def self.get_list(element)
      list = []
      element.each_element('b:itemList') { |itemList|  
        itemList.each_element('b:dataElement')  { |dataElement| list << get_element(dataElement) }
        itemList.each_element('b:partialOrder') { |partialOrder| list << get_list(partialOrder) }
      }
      list
    end
    
    def self.get_metadata(element)
      list = []
      element.each_element('s:mimeTypes') { |mimeTypes|
        mimeTypes.each_element('s:mimeType')  { |mimeType| list << mimeType.text }
      }
      list
    end
    
    def self.get_element(element)
      element.each_element('b:dataElementData') { |data| return Base64.decode64(data.text) }
    end
    
  end
  
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
mannie-taverna-scufl-0.6.0 lib/baclava/reader.rb
mannie-taverna-scufl-0.6.1 lib/baclava/reader.rb
mannie-taverna-scufl-0.6.2 lib/baclava/reader.rb
mannie-taverna-scufl-0.7.0 lib/baclava/reader.rb
mannie-taverna-scufl-0.7.1 lib/baclava/reader.rb
mannie-taverna_scufl-0.6.0 lib/baclava/reader.rb
myGrid-taverna-scufl-0.6.0 lib/baclava/reader.rb
taverna-scufl-0.7.2 lib/baclava/reader.rb
taverna-scufl-0.7.1 lib/baclava/reader.rb