Class: Nagios::MkLiveStatus::Filter::Negate

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

Overview

This class is used to make a logical “NOT” operator for the filter expression.

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(expr) ⇒ Negate

Create a new “Not” operator for the expression.

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



15
16
17
18
19
20
21
22
# File 'lib/nagios_mklivestatus/filter/negate.rb', line 15

def initialize(expr)
  if not expr.is_a? Nagios::MkLiveStatus::Filter
    raise QueryException.new("The operand for a NEGATE expression must be a filter expression.")
  end
  
  @expression = expr
  
end

Instance Method Details

#get_expressionObject

Return the expression under the “Negate”. It’s used by the to_s method in order to remove the overflow of Negate expression.



28
29
30
# File 'lib/nagios_mklivestatus/filter/negate.rb', line 28

def get_expression
  return @expression
end

#to_sObject

Convert the current “Negate” expression into a nagios query string.

Filter: ...
Negate:

If the sub expression is also a Negate, it returns the sub-sub expression without negating it.



39
40
41
42
43
44
45
46
47
48
# File 'lib/nagios_mklivestatus/filter/negate.rb', line 39

def to_s
  if @expression.is_a? Nagios::MkLiveStatus::Filter::Negate
    return @expression.get_expression.to_s
  else
    negate_arr = []
    negate_arr.push @expression.to_s
    negate_arr.push "Negate: "
    return negate_arr.join("\n")
  end
end