lib/vissen/input/message_factory.rb in vissen-input-0.2.2 vs lib/vissen/input/message_factory.rb in vissen-input-0.3.0

- old
+ new

@@ -21,11 +21,11 @@ # class MessageFactory # @param matchers [nil, Array<Matcher>] the matchers to use when building # messages. If provided the factory will be frozen after creation. def initialize(matchers = nil) - @lookup_table = Array.new(16) + @lookup_table = Array.new(16) { [] } @matchers = [] return unless matchers matchers.each { |m| add_matcher m } @@ -77,24 +77,13 @@ entry = @lookup_table[status] matcher = entry&.find { |m| m.match? data } unless matcher matcher = @matchers.find { |m| m.match? data } - add_to_lookup matcher, data if matcher + @lookup_table[status] << matcher if matcher end matcher - end - - def add_to_lookup(matcher, data) - status = data[0] >> 4 - entry = @lookup_table[status] - - if entry - entry << matcher - else - @lookup_table[status] = [matcher] - end end end end end