Sha256: 0cd311ced16cc98dce8da6ff7111db18ccd0ad519abf88df587fa7f2c4eca854
Contents?: true
Size: 1.39 KB
Versions: 10
Compression:
Stored size: 1.39 KB
Contents
class Ecu class SignalListComparison def initialize(left, right) unless left.is_a?(SignalList) && right.is_a?(SignalList) fail "Can only merge SignalLists (left: #{left.class}, right: #{right.class})!" end @left = left.map(&:name) @right = right.map(&:name) @unified_headers = left.headers + right.headers @unified_subheaders = left.subheaders + right.subheaders @names = Hash.new end def names(criterion) @names[criterion] ||= \ case criterion when :left_exclusive then left - right when :right_exclusive then right - left when :common then left & right when :equal then left & right when :nonequal then [] else fail "Unknown criterion #{criterion}" end end def left_exclusive names(:left_exclusive).map { |name| left.fetch(name) } end def right_exclusive names(:right_exclusive).map { |name| right.fetch(name) } end def merge(priority: :right) SignalList.new \ ( names(:left_exclusive).map { |n| left.fetch(n) } + names(:right_exclusive).map { |n| right.fetch(n) } + names(:common).map { |n| left.fetch(n) } ), @unified_headers, @unified_subheaders end private attr_reader :left, :right end end
Version data entries
10 entries across 10 versions & 1 rubygems