Class: AmqpTopicBinding::Matcher
- Inherits:
-
Object
- Object
- AmqpTopicBinding::Matcher
- Defined in:
- lib/amqp_topic_binding/matcher.rb
Instance Method Summary collapse
-
#initialize(pattern) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(routing_key) ⇒ Boolean
Constructor Details
#initialize(pattern) ⇒ Matcher
Returns a new instance of Matcher.
3 4 5 6 |
# File 'lib/amqp_topic_binding/matcher.rb', line 3 def initialize(pattern) @pattern = pattern || '' @pattern_parts = @pattern.split('.') end |
Instance Method Details
#matches?(routing_key) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/amqp_topic_binding/matcher.rb', line 8 def matches?(routing_key) if routing_key.nil? || routing_key == '' return false end if @pattern == routing_key return true end routing_key_parts = routing_key.split('.') if @pattern_parts.length > routing_key_parts.length return false end last_checked_index = 0 @pattern_parts.each_with_index do |pattern_part, index| if pattern_part == '#' return true end routing_key_part = routing_key_parts[index] if pattern_part != '*' && pattern_part != routing_key_part return false end last_checked_index = index end if routing_key_parts.length > (last_checked_index + 1) return false end return true end |