Class: Dor::Workflow::Response::Workflow

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/workflow/response/workflow.rb

Overview

The response from asking the server about a workflow for an item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml:) ⇒ Workflow

Returns a new instance of Workflow.



8
9
10
# File 'lib/dor/workflow/response/workflow.rb', line 8

def initialize(xml:)
  @xml = xml
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



42
43
44
# File 'lib/dor/workflow/response/workflow.rb', line 42

def xml
  @xml
end

Instance Method Details

#active_for?(version:) ⇒ Boolean

Parameters:

  • version (Integer)

    the version we are checking for.

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/dor/workflow/response/workflow.rb', line 21

def active_for?(version:)
  result = ng_xml.at_xpath("/workflow/process[@version=#{version}]")
  result ? true : false
end

#complete?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/dor/workflow/response/workflow.rb', line 38

def complete?
  ng_xml.xpath("/workflow/process[@version=#{version}]/@status").map(&:value).all? { |p| %w[skipped completed].include?(p) }
end

#empty?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dor/workflow/response/workflow.rb', line 34

def empty?
  ng_xml.xpath('/workflow/process').empty?
end

#pidObject



12
13
14
# File 'lib/dor/workflow/response/workflow.rb', line 12

def pid
  workflow['objectId']
end

#process_for_recent_version(name:) ⇒ Object

Returns the process, for the most recent version that matches the given name:



27
28
29
30
31
32
# File 'lib/dor/workflow/response/workflow.rb', line 27

def process_for_recent_version(name:)
  nodes = process_nodes_for(name: name)
  node = nodes.max { |a, b| a.attr('version').to_i <=> b.attr('version').to_i }
  attributes = node ? node.attributes.to_h { |k, v| [k.to_sym, v.value] } : {}
  Process.new(parent: self, **attributes)
end

#workflow_nameObject



16
17
18
# File 'lib/dor/workflow/response/workflow.rb', line 16

def workflow_name
  workflow['id']
end