2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
class UnionFinder
|
|
|
|
def find_union(segments, klass)
|
2018-09-11 11:31:34 -04:00
|
|
|
unless klass < FromUnion
|
|
|
|
raise TypeError, "#{klass.inspect} must include the FromUnion module"
|
|
|
|
end
|
2016-03-20 16:03:53 -04:00
|
|
|
|
2018-09-11 11:31:34 -04:00
|
|
|
if segments.length > 1
|
|
|
|
klass.from_union(segments)
|
2016-03-20 16:03:53 -04:00
|
|
|
else
|
|
|
|
segments.first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|