Class: Document::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/document/report.rb

Class Method Summary collapse

Class Method Details

.add_processor(element, report) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/document/report.rb', line 59

def self.add_processor(element, report)
  processor = Processor.new
  
  name = element.attribute('name')
  processor.name = name.value if name
    
  if element.has_elements?
     firstElement = element.elements[1]
    case firstElement.name
    when 'ProcessComplete'
         processor.status = 'COMPLETE'
      processor.time = firstElement.attribute('TimeStamp')
    when 'ProcessScheduled'
         processor.status = 'SCHEDULED'
      processor.time = firstElement.attribute('TimeStamp')
    when 'InvokingWithIteration'
      processor.status = 'ITERATING'
      processor.time = firstElement.attribute('TimeStamp')
      processor.number = firstElement.attribute('IterationNumber')
      processor.total = firstElement.attribute('IterationTotal')      
    when 'ServiceFailure'
      processor.status = 'FAILED'
      processor.time = firstElement.attribute('TimeStamp')
    else
      processor.status = 'UNKNOWN'
    end
  end
  report.processors.push processor   
end

.create_report(element) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/document/report.rb', line 43

def self.create_report(element)
  report = Report.new
  
  id = element.attribute('workflowId')
  report.id = id.value if id
  
  status = element.attribute('workflowStatus')
  report.status = status.value if status
  
  element.elements['processorList'].each_element('processor') { |processor|
    add_processor(processor, report)
  }
  
  report
end

.read(report) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/document/report.rb', line 28

def self.read(report)
  if report.kind_of?(REXML::Document)
    document = report
  else
    document = REXML::Document.new(report)
  end
  root = document.root
        
  return nil if not root
              
  raise root.name + "Doesn't appear to be a workflow report!" if root.name != "workflowReport"
              
  create_report(root)
end