Class: PackAPI::Querying::AbstractNumericFilter

Inherits:
DiscoverableFilter show all
Defined in:
lib/pack_api/querying/abstract_numeric_filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DiscoverableFilter

#filter_name, filter_name, #type

Methods inherited from AbstractFilter

#apply_to, #present?

Constructor Details

#initialize(operator:, value:) ⇒ AbstractNumericFilter

Returns a new instance of AbstractNumericFilter.



23
24
25
26
27
# File 'lib/pack_api/querying/abstract_numeric_filter.rb', line 23

def initialize(operator:, value:)
  super()
  @operator = operator
  @value = value
end

Instance Attribute Details

#operatorObject

Returns the value of attribute operator.



5
6
7
# File 'lib/pack_api/querying/abstract_numeric_filter.rb', line 5

def operator
  @operator
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/pack_api/querying/abstract_numeric_filter.rb', line 5

def value
  @value
end

Class Method Details

.definitionObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pack_api/querying/abstract_numeric_filter.rb', line 11

def self.definition(**)
  operators = [
    PackAPI::Types::FilterOption.new(label: 'Greater than', value: '>'),
    PackAPI::Types::FilterOption.new(label: 'Greater than or equal to', value: '>='),
    PackAPI::Types::FilterOption.new(label: 'Equal to', value: '='),
    PackAPI::Types::FilterOption.new(label: 'Less than or equal to', value: '<='),
    PackAPI::Types::FilterOption.new(label: 'Less than', value: '<')
  ]

  PackAPI::Types::NumericFilterDefinition.new(name: filter_name, operators:)
end

.typeObject



7
8
9
# File 'lib/pack_api/querying/abstract_numeric_filter.rb', line 7

def self.type
  :numeric
end

Instance Method Details

#to_hObject

Raises:

  • (NotImplementedError)


31
32
33
34
35
# File 'lib/pack_api/querying/abstract_numeric_filter.rb', line 31

def to_h
  raise NotImplementedError unless self.class.filter_name

  { self.class.filter_name => { operator:, value: } }
end