Class: IcingaApi::Filter
- Inherits:
-
Object
- Object
- IcingaApi::Filter
- Defined in:
- lib/icinga_api/filter.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #&(other) ⇒ Object
-
#initialize(field = nil, operator = nil, value = nil) ⇒ Filter
constructor
A new instance of Filter.
- #to_json ⇒ Object
- #|(other) ⇒ Object
Constructor Details
#initialize(field = nil, operator = nil, value = nil) ⇒ Filter
Returns a new instance of Filter.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/icinga_api/filter.rb', line 7 def initialize(field=nil, operator=nil, value=nil) @multi = false if field.class == Hash # only for internal use @data = field @multi = true else # normal use @data = { type: "atom", field: [ field ], method: [ operator ], value: [ value ] } end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/icinga_api/filter.rb', line 5 def data @data end |
Instance Method Details
#&(other) ⇒ Object
20 21 22 23 |
# File 'lib/icinga_api/filter.rb', line 20 def &(other) other = Marshal.load(Marshal.dump(other)) self.class.new ({ type: 'AND', field: [@data, other.data] }) end |
#to_json ⇒ Object
32 33 34 35 36 |
# File 'lib/icinga_api/filter.rb', line 32 def to_json # icinga always wants a AND or OR construct, the hell knows why return (self & self).to_json unless @multi @data.to_json end |
#|(other) ⇒ Object
26 27 28 29 |
# File 'lib/icinga_api/filter.rb', line 26 def |(other) other = Marshal.load(Marshal.dump(other)) self.class.new ({ type: 'OR', field: [@data, other.data] }) end |