Module: TavernaPlayer::Concerns::Utils

Extended by:
ActiveSupport::Concern
Included in:
Controllers::RunsController, Models::RunPort
Defined in:
lib/taverna_player/concerns/utils.rb

Instance Method Summary collapse

Instance Method Details

#list_depth(list, depth = 0) ⇒ Object

Sometimes we need to test an array’s depth to check that it matches a port’s depth. An empty list has depth 1, because it is a list.



30
31
32
33
# File 'lib/taverna_player/concerns/utils.rb', line 30

def list_depth(list, depth = 0)
  return depth if !list.is_a?(Array)
  list.empty? ? depth + 1 : list.map { |l| list_depth(l, depth + 1) }.max
end

#recurse_into_lists(list, indexes) ⇒ Object

Taverna can have arbitrary (therefore effectively “infinite”) port depths so we need to recurse into them. This code is common across a number of other modules.



22
23
24
25
26
# File 'lib/taverna_player/concerns/utils.rb', line 22

def recurse_into_lists(list, indexes)
  return list if indexes.empty? || !list.is_a?(Array)
  i = indexes.shift
  recurse_into_lists(list[i], indexes)
end