Class: Courier::Audiences::SingleFilterConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/audiences/types/single_filter_config.rb

Overview

A single filter to use for filtering

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, path:, operator:, additional_properties: nil) ⇒ Audiences::SingleFilterConfig

Parameters:

  • value (String)

    The value to use for filtering

  • path (String)

    The attribe name from profile whose value will be operated against the filter value

  • operator (Audiences::Operator)

    The operator to use for filtering

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



17
18
19
20
21
22
23
24
25
26
# File 'lib/trycourier/audiences/types/single_filter_config.rb', line 17

def initialize(value:, path:, operator:, additional_properties: nil)
  # @type [String] The value to use for filtering
  @value = value
  # @type [String] The attribe name from profile whose value will be operated against the filter value
  @path = path
  # @type [Audiences::Operator] The operator to use for filtering
  @operator = operator
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



10
11
12
# File 'lib/trycourier/audiences/types/single_filter_config.rb', line 10

def additional_properties
  @additional_properties
end

#operatorObject (readonly)

Returns the value of attribute operator.



10
11
12
# File 'lib/trycourier/audiences/types/single_filter_config.rb', line 10

def operator
  @operator
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/trycourier/audiences/types/single_filter_config.rb', line 10

def path
  @path
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/trycourier/audiences/types/single_filter_config.rb', line 10

def value
  @value
end

Class Method Details

.from_json(json_object:) ⇒ Audiences::SingleFilterConfig

Deserialize a JSON object to an instance of SingleFilterConfig

Parameters:

  • json_object (JSON)

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/trycourier/audiences/types/single_filter_config.rb', line 32

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  value = struct.value
  path = struct.path
  if parsed_json["operator"].nil?
    operator = nil
  else
    operator = parsed_json["operator"].to_json
    operator = Audiences::Operator.from_json(json_object: operator)
  end
  new(value: value, path: path, operator: operator, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


57
58
59
60
61
# File 'lib/trycourier/audiences/types/single_filter_config.rb', line 57

def self.validate_raw(obj:)
  obj.value.is_a?(String) != false || raise("Passed value for field obj.value is not the expected type, validation failed.")
  obj.path.is_a?(String) != false || raise("Passed value for field obj.path is not the expected type, validation failed.")
  Audiences::Operator.validate_raw(obj: obj.operator)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of SingleFilterConfig to a JSON object

Returns:

  • (JSON)


49
50
51
# File 'lib/trycourier/audiences/types/single_filter_config.rb', line 49

def to_json(*_args)
  { "value": @value, "path": @path, "operator": @operator }.to_json
end