Class: Nagios::MkLiveStatus::Filter::And

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

Overview

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

If one of the filter expression is also an “AND”, 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) ⇒ And

Create a new “AND” 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/and.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 AND expression must be filter expressions.")
  end
  
  @expressions = Array.new
  if left_expr.is_a? Nagios::MkLiveStatus::Filter::And
    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::And
    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 “AND”. It’s used by the new method in order to get all “AND” expressions into the same object.



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

def get_expressions
  return @expressions
end

#to_sObject

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

Filter: ...
Filter: ...
And: 2


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

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