Class: SearchCriteria::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/domain/search_criteria/model.rb

Overview

Nested Filter class for search criteria filters

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field:, operator:, value: nil, values: nil, lower: nil, upper: nil) ⇒ Filter

Returns a new instance of Filter.



17
18
19
20
21
22
23
24
25
26
# File 'lib/domain/search_criteria/model.rb', line 17

def initialize(
  field:, operator:, value: nil, values: nil, lower: nil, upper: nil
)
  @field = field
  @operator = operator
  @value = value
  @values = values
  @lower = lower
  @upper = upper
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



15
16
17
# File 'lib/domain/search_criteria/model.rb', line 15

def field
  @field
end

#lowerObject

Returns the value of attribute lower.



15
16
17
# File 'lib/domain/search_criteria/model.rb', line 15

def lower
  @lower
end

#operatorObject

Returns the value of attribute operator.



15
16
17
# File 'lib/domain/search_criteria/model.rb', line 15

def operator
  @operator
end

#upperObject

Returns the value of attribute upper.



15
16
17
# File 'lib/domain/search_criteria/model.rb', line 15

def upper
  @upper
end

#valueObject

Returns the value of attribute value.



15
16
17
# File 'lib/domain/search_criteria/model.rb', line 15

def value
  @value
end

#valuesObject

Returns the value of attribute values.



15
16
17
# File 'lib/domain/search_criteria/model.rb', line 15

def values
  @values
end

Class Method Details

.from_json(data) ⇒ Object

Class method to create a Filter from a JSON string



29
30
31
32
33
34
35
36
37
38
# File 'lib/domain/search_criteria/model.rb', line 29

def self.from_json(data)
  new(
    field: data['field'],
    operator: data['operator'],
    value: data['value'],
    values: data['values'],
    lower: data['lower'],
    upper: data['upper']
  )
end

.from_site_id(id) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/domain/search_criteria/model.rb', line 40

def self.from_site_id(id)
  new(
    field: 'site-id',
    operator: 'in',
    values: [id]
  )
end

Instance Method Details

#to_json(*_options) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/domain/search_criteria/model.rb', line 48

def to_json(*_options)
  {
    field:,
    operator:,
    value:,
    values:,
    lower:,
    upper:
  }.compact
end