Class: Nagios::MkLiveStatus::Filter::Or

Inherits:
Nagios::MkLiveStatus::Filter show all
Includes:
Nagios::MkLiveStatus
Defined in:
lib/nagios_mklivestatus/filter/or.rb

Overview

This class is used to make a logical “OR” operator between two filter expressions.

If one of the filter expression is also an “OR”, it takes all the expressions of the operator as its own.

Author

Esco-lan Team ([email protected])

Copyright

Copyright © 2012 GIP RECIA

License

General Public Licence

Instance Method Summary collapse

Methods included from Nagios::MkLiveStatus

init, #logger

Constructor Details

#initialize(left_expr, right_expr) ⇒ Or

Create a new “OR” operator between left and right expressions.

Those expressions must be of type Nagios::MkLiveStatus::Filter



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nagios_mklivestatus/filter/or.rb', line 18

def initialize(left_expr, right_expr)
  if not left_expr.is_a? Nagios::MkLiveStatus::Filter or not right_expr.is_a? Nagios::MkLiveStatus::Filter
    raise QueryException.new("The left and the right operand for an OR expression must be filter expressions.")
  end
  
  @expressions = Array.new
  if left_expr.is_a? Nagios::MkLiveStatus::Filter::Or
    left_expr.get_expressions.each do |expr|
      @expressions.push expr
    end
  else
    @expressions.push left_expr
  end
  
  if right_expr.is_a? Nagios::MkLiveStatus::Filter::Or
    right_expr.get_expressions.each do |expr|
      @expressions.push expr
    end
  else
    @expressions.push right_expr
  end

end

Instance Method Details

#get_expressionsObject

Return all the expressions under the “OR”. It’s used by the new method in order to get all “OR” expressions into the same object.



46
47
48
# File 'lib/nagios_mklivestatus/filter/or.rb', line 46

def get_expressions
  return @expressions
end

#to_sObject

Convert the current “OR” expression into a nagios query string

Filter: ...
Filter: ...
Or: 2


56
57
58
59
60
61
62
63
# File 'lib/nagios_mklivestatus/filter/or.rb', line 56

def to_s
  or_arr = []
  @expressions.each do |expr|
    or_arr.push expr.to_s
  end
  or_arr.push "Or: #{@expressions.length}"
  return or_arr.join("\n")
end