module TavernaPlayer::Concerns::Utils
Public Instance Methods
list_depth(list, depth = 0)
click to toggle source
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.
# 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)
click to toggle source
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.
# 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