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.



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

def initialize(field, operator, value = '')
  @field    = field.upcase
  @operator = 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



282
283
284
# File 'lib/nexpose/filter.rb', line 282

def field
  @field
end

#operatorObject

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



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

def operator
  @operator
end

#valueObject

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



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

def value
  @value
end

Class Method Details

.parse(json) ⇒ Object



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

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.



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

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