Class: SourceRoute::TpFilter
Instance Attribute Summary collapse
-
#cond ⇒ Object
Returns the value of attribute cond.
Instance Method Summary collapse
-
#block_it?(tp) ⇒ Boolean
to improve performance, we didnt assign tp as instance variable.
-
#initialize(condition) ⇒ TpFilter
constructor
A new instance of TpFilter.
- #negative_check(tp) ⇒ Object
- #positives_check(tp) ⇒ Object
Constructor Details
#initialize(condition) ⇒ TpFilter
Returns a new instance of TpFilter.
5 6 7 |
# File 'lib/source_route/tp_filter.rb', line 5 def initialize(condition) @cond = condition end |
Instance Attribute Details
#cond ⇒ Object
Returns the value of attribute cond.
4 5 6 |
# File 'lib/source_route/tp_filter.rb', line 4 def cond @cond end |
Instance Method Details
#block_it?(tp) ⇒ Boolean
to improve performance, we didnt assign tp as instance variable
10 11 12 13 14 |
# File 'lib/source_route/tp_filter.rb', line 10 def block_it?(tp) return true if negative_check(tp) return false if positives_check(tp) true end |
#negative_check(tp) ⇒ Object
16 17 18 19 20 |
# File 'lib/source_route/tp_filter.rb', line 16 def negative_check(tp) cond.negatives.any? do |method_key, value| tp.send(method_key).to_s =~ Regexp.new(value) end end |
#positives_check(tp) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/source_route/tp_filter.rb', line 22 def positives_check(tp) return true if cond.positives == {} cond.positives.any? do |method_key, value| tp.send(method_key).to_s =~ Regexp.new(value) end end |