Class: RShade::Filter::FilterComposition
- Includes:
- Enumerable
- Defined in:
- lib/rshade/filter/filter_composition.rb
Constant Summary collapse
- AND_OP =
:and- OR_OP =
:or- UNARY_OP =
:unary
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(event) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
-
#each {|value| ... } ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity.
- #filter(type, &block) ⇒ Object
-
#filter_results(event) ⇒ Object
for debug purposes, show each filter and result of evaluation.
-
#initialize(value, left = nil, right = nil) ⇒ FilterComposition
constructor
A new instance of FilterComposition.
Constructor Details
#initialize(value, left = nil, right = nil) ⇒ FilterComposition
Returns a new instance of FilterComposition.
15 16 17 18 19 |
# File 'lib/rshade/filter/filter_composition.rb', line 15 def initialize(value, left = nil, right = nil) @value = value @left = left @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
10 11 12 |
# File 'lib/rshade/filter/filter_composition.rb', line 10 def left @left end |
#parent ⇒ Object
Returns the value of attribute parent.
11 12 13 |
# File 'lib/rshade/filter/filter_composition.rb', line 11 def parent @parent end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
10 11 12 |
# File 'lib/rshade/filter/filter_composition.rb', line 10 def right @right end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/rshade/filter/filter_composition.rb', line 10 def value @value end |
Class Method Details
.build(arr) ⇒ Object
56 57 58 |
# File 'lib/rshade/filter/filter_composition.rb', line 56 def self.build(arr) ::RShade::Filter::FilterBuilder.build(arr) end |
Instance Method Details
#call(event) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rshade/filter/filter_composition.rb', line 22 def call(event) case value when UNARY_OP left&.call(event) when AND_OP left&.call(event) && right&.call(event) when OR_OP left&.call(event) || right&.call(event) else value.call(event) end end |
#each {|value| ... } ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity
36 37 38 39 40 |
# File 'lib/rshade/filter/filter_composition.rb', line 36 def each(&block) yield value unless left && right left&.each(&block) right&.each(&block) end |
#filter(type, &block) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/rshade/filter/filter_composition.rb', line 42 def filter(type, &block) filter = find do |f| f.is_a? type end filter&.config(&block) end |
#filter_results(event) ⇒ Object
for debug purposes, show each filter and result of evaluation
50 51 52 53 54 |
# File 'lib/rshade/filter/filter_composition.rb', line 50 def filter_results(event) each_with_object([]) do |filter, arr| arr << [filter, filter.call(event)] end end |