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