Class: Dor::Workflow::Response::Workflow
- Inherits:
-
Object
- Object
- Dor::Workflow::Response::Workflow
- 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
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
-
#active_for?(version:) ⇒ Boolean
Check if there are any processes for the provided version.
- #complete? ⇒ Boolean
-
#complete_for?(version:) ⇒ Boolean
Check if all processes are skipped or complete for the provided version.
- #empty? ⇒ Boolean
- #incomplete_processes ⇒ Object
- #incomplete_processes_for(version:) ⇒ Object
-
#initialize(xml:) ⇒ Workflow
constructor
A new instance of Workflow.
- #pid ⇒ Object
-
#process_for_recent_version(name:) ⇒ Object
Returns the process, for the most recent version that matches the given name:.
- #workflow_name ⇒ Object
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
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
59 60 61 |
# File 'lib/dor/workflow/response/workflow.rb', line 59 def xml @xml end |
Instance Method Details
#active_for?(version:) ⇒ Boolean
Check if there are any processes for the provided version.
22 23 24 25 |
# File 'lib/dor/workflow/response/workflow.rb', line 22 def active_for?(version:) result = ng_xml.at_xpath("/workflow/process[@version=#{version}]") result ? true : false end |
#complete? ⇒ Boolean
45 46 47 |
# File 'lib/dor/workflow/response/workflow.rb', line 45 def complete? complete_for?(version: version) end |
#complete_for?(version:) ⇒ Boolean
Check if all processes are skipped or complete for the provided version.
40 41 42 43 |
# File 'lib/dor/workflow/response/workflow.rb', line 40 def complete_for?(version:) # ng_xml.xpath("/workflow/process[@version=#{version}]/@status").map(&:value).all? { |p| %w[skipped completed].include?(p) } incomplete_processes_for(version: version).empty? end |
#empty? ⇒ Boolean
34 35 36 |
# File 'lib/dor/workflow/response/workflow.rb', line 34 def empty? ng_xml.xpath('/workflow/process').empty? end |
#incomplete_processes ⇒ Object
55 56 57 |
# File 'lib/dor/workflow/response/workflow.rb', line 55 def incomplete_processes incomplete_processes_for(version: version) end |
#incomplete_processes_for(version:) ⇒ Object
49 50 51 52 53 |
# File 'lib/dor/workflow/response/workflow.rb', line 49 def incomplete_processes_for(version:) process_nodes = ng_xml.xpath("/workflow/process[@version=#{version}]") incomplete_process_nodes = process_nodes.reject { |process_node| %w[skipped completed].include?(process_node.attr('status')) } incomplete_process_nodes.map { |process_node| to_process(process_node) } end |
#pid ⇒ Object
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:
28 29 30 31 32 |
# File 'lib/dor/workflow/response/workflow.rb', line 28 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 } to_process(node) end |
#workflow_name ⇒ Object
16 17 18 |
# File 'lib/dor/workflow/response/workflow.rb', line 16 def workflow_name workflow['id'] end |