Class: Nexpose::Criterion

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/filter.rb

Overview

Individual search criterion.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, operator, value = '') ⇒ Criterion

Returns a new instance of Criterion.



290
291
292
293
294
295
296
297
# File 'lib/nexpose/filter.rb', line 290

def initialize(field, operator, value = '')
  @field, @operator = field.upcase, operator.upcase
  if value.is_a? Array
    @value = value.map(&:to_s)
  else
    @value = value.to_s
  end
end

Instance Attribute Details

#fieldObject

Search field. One of Nexpose::Search::Field



284
285
286
# File 'lib/nexpose/filter.rb', line 284

def field
  @field
end

#operatorObject

Search operator. One of Nexpose::Search::Operator



286
287
288
# File 'lib/nexpose/filter.rb', line 286

def operator
  @operator
end

#valueObject

Search value. A search string or one of Nexpose::Search::Value



288
289
290
# File 'lib/nexpose/filter.rb', line 288

def value
  @value
end

Class Method Details

.parse(json) ⇒ Object



307
308
309
310
311
# File 'lib/nexpose/filter.rb', line 307

def self.parse(json)
  Criterion.new(json['metadata']['fieldName'],
                json['operator'],
                json['values'])
end

Instance Method Details

#to_hObject

Convert this object into the map format expected by Nexpose.



301
302
303
304
305
# File 'lib/nexpose/filter.rb', line 301

def to_h
  { 'metadata' => { 'fieldName' => field },
    'operator' => operator,
    'values' => Array(value) }
end