Class: Super::Filter::FormObject::OperatorForm

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

Constant Summary collapse

NULLARY =
:_apply

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator:, params:) ⇒ OperatorForm

Returns a new instance of OperatorForm.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/super/filter/form_object.rb', line 40

def initialize(operator:, params:)
  @operator = operator
  @params = params || {}
  query_parameter_keys = operator.query_parameter_keys
  query_parameter_keys = [NULLARY] if query_parameter_keys.empty?
  @specified_values =
    query_parameter_keys
    .map { |key| [key, @params[key].presence&.strip] }
    .to_h

  @specified_values.each do |key, value|
    define_singleton_method(key) { value }
  end
end

Instance Attribute Details

#operatorObject (readonly)

Returns the value of attribute operator.



59
60
61
# File 'lib/super/filter/form_object.rb', line 59

def operator
  @operator
end

#specified_valuesObject (readonly)

Returns the value of attribute specified_values.



60
61
62
# File 'lib/super/filter/form_object.rb', line 60

def specified_values
  @specified_values
end

Instance Method Details

#each_fieldObject



66
67
68
69
70
71
72
# File 'lib/super/filter/form_object.rb', line 66

def each_field
  return enum_for(:each_field) if !block_given?

  @specified_values.each do |key, _value|
    yield(key)
  end
end

#identifierObject



62
63
64
# File 'lib/super/filter/form_object.rb', line 62

def identifier
  @operator.identifier
end

#specified?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/super/filter/form_object.rb', line 55

def specified?
  @specified_values.any? { |_key, value| value }
end