Class: Nexpose::Criteria
- Inherits:
-
Object
- Object
- Nexpose::Criteria
- Defined in:
- lib/nexpose/filter.rb
Overview
Join search criteria for an asset filter search or dynamic asset group.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#criteria ⇒ Object
Array of criteria to match against.
-
#match ⇒ Object
Whether to match any or all filters.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(criterion) ⇒ Object
-
#_to_payload ⇒ Object
Generate the payload needed for a POST request for Asset Filter.
-
#initialize(criteria = [], match = 'AND') ⇒ Criteria
constructor
A new instance of Criteria.
- #to_h ⇒ Object
-
#to_json ⇒ Object
Convert this object into the format expected by Nexpose.
Constructor Details
#initialize(criteria = [], match = 'AND') ⇒ Criteria
Returns a new instance of Criteria.
322 323 324 325 |
# File 'lib/nexpose/filter.rb', line 322 def initialize(criteria = [], match = 'AND') @criteria = Array(criteria) @match = match.upcase end |
Instance Attribute Details
#criteria ⇒ Object
Array of criteria to match against.
320 321 322 |
# File 'lib/nexpose/filter.rb', line 320 def criteria @criteria end |
#match ⇒ Object
Whether to match any or all filters. One of ‘OR’ or ‘AND’.
318 319 320 |
# File 'lib/nexpose/filter.rb', line 318 def match @match end |
Class Method Details
.parse(json) ⇒ Object
353 354 355 356 357 358 359 360 361 |
# File 'lib/nexpose/filter.rb', line 353 def self.parse(json) # The call returns empty JSON, so default to 'AND' if not present. operator = json['operator'] || 'AND' ret = Criteria.new([], operator) json['criteria'].each do |c| ret.criteria << Criterion.parse(c) end ret end |
Instance Method Details
#<<(criterion) ⇒ Object
349 350 351 |
# File 'lib/nexpose/filter.rb', line 349 def <<(criterion) criteria << criterion end |
#_to_payload ⇒ Object
Generate the payload needed for a POST request for Asset Filter.
340 341 342 343 344 345 346 347 |
# File 'lib/nexpose/filter.rb', line 340 def _to_payload { 'dir' => -1, 'results' => -1, 'sort' => 'assetIP', 'startIndex' => -1, 'table-id' => 'assetfilter', 'searchCriteria' => to_json } end |
#to_h ⇒ Object
327 328 329 330 |
# File 'lib/nexpose/filter.rb', line 327 def to_h { 'operator' => @match, 'criteria' => @criteria.map(&:to_h) } end |
#to_json ⇒ Object
Convert this object into the format expected by Nexpose.
334 335 336 |
# File 'lib/nexpose/filter.rb', line 334 def to_json JSON.generate(to_h) end |