Sha256: e23e290d840212aa520c3cf24d8d2036ba5163f0b3ef4f2f2bfb1349882e1fba

Contents?: true

Size: 1.46 KB

Versions: 10

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Dor
  module Workflow
    module Response
      # The response from asking the server about a workflow for an item
      class Workflow
        def initialize(xml:)
          @xml = xml
        end

        def pid
          workflow['objectId']
        end

        def workflow_name
          workflow['id']
        end

        def repository
          workflow['repository']
        end

        # @param [Integer] version the version we are checking for.
        def active_for?(version:)
          result = ng_xml.at_xpath("/workflow/process[@version=#{version}]")
          result ? true : false
        end

        # Returns the process, for the most recent version that matches the given name:
        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

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

        attr_reader :xml

        private

        def workflow
          ng_xml.at_xpath('workflow')
        end

        def process_nodes_for(name:)
          ng_xml.xpath("/workflow/process[@name = '#{name}']")
        end

        def ng_xml
          @ng_xml ||= Nokogiri::XML(@xml)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dor-workflow-client-3.14.0 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.13.0 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.12.0 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.11.1 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.11.0 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.10.0 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.9.0 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.8.0 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.7.0 lib/dor/workflow/response/workflow.rb
dor-workflow-client-3.6.0 lib/dor/workflow/response/workflow.rb