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

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

Overview

The response form 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.



10
11
12
# File 'lib/dor/models/response/workflow.rb', line 10

def initialize(xml:)
  @xml = xml
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



40
41
42
# File 'lib/dor/models/response/workflow.rb', line 40

def xml
  @xml
end

Instance Method Details

#active_for?(version:) ⇒ Boolean

Parameters:

  • version (Integer)

    the version we are checking for.

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/dor/models/response/workflow.rb', line 23

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

#empty?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dor/models/response/workflow.rb', line 36

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

#pidObject



14
15
16
# File 'lib/dor/models/response/workflow.rb', line 14

def pid
  ng_xml.at_xpath('/workflow/@objectId').text
end

#process_for_recent_version(name:) ⇒ Object

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



29
30
31
32
33
34
# File 'lib/dor/models/response/workflow.rb', line 29

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 ? Hash[node.attributes.collect { |k, v| [k.to_sym, v.value] }] : {}
  Process.new(parent: self, **attributes)
end

#workflow_nameObject



18
19
20
# File 'lib/dor/models/response/workflow.rb', line 18

def workflow_name
  ng_xml.at_xpath('/workflow/@id').text
end