Class: Baclava::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/baclava/reader.rb

Class Method Summary collapse

Class Method Details

.create_data_map(element) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/baclava/reader.rb', line 21

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')  { || data.annotation = () }
      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

.get_element(element) ⇒ Object



55
56
57
# File 'lib/baclava/reader.rb', line 55

def self.get_element(element)
  element.each_element('b:dataElementData') { |data| return Base64.decode64(data.text) }
end

.get_list(element) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/baclava/reader.rb', line 38

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

.get_metadata(element) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/baclava/reader.rb', line 47

def self.(element)
  list = []
  element.each_element('s:mimeTypes') { |mimeTypes|
    mimeTypes.each_element('s:mimeType')  { |mimeType| list << mimeType.text }
  }
  list
end

.read(xml) ⇒ Object

Reads a baclava document amd returns a hash of Document::Data objects



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/baclava/reader.rb', line 9

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